Skip to content

Commit

Permalink
En/arango migrations (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
Umang01-hash authored Feb 12, 2025
1 parent 980cfae commit 2bcdc8e
Show file tree
Hide file tree
Showing 17 changed files with 1,301 additions and 28 deletions.
15 changes: 15 additions & 0 deletions docs/advanced-guide/injecting-databases-drivers/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,21 @@ added using the `app.AddArangoDB()` method, and users can use ArangoDB across th

```go
type ArangoDB interface {
// CreateDB creates a new database in ArangoDB.
CreateDB(ctx context.Context, database string) error
// DropDB deletes an existing database in ArangoDB.
DropDB(ctx context.Context, database string) error

// CreateCollection creates a new collection in a database with specified type.
CreateCollection(ctx context.Context, database, collection string, isEdge bool) error
// DropCollection deletes an existing collection from a database.
DropCollection(ctx context.Context, database, collection string) error

// CreateGraph creates a new graph in a database.
CreateGraph(ctx context.Context, database, graph string, edgeDefinitions any) error
// DropGraph deletes an existing graph from a database.
DropGraph(ctx context.Context, database, graph string) error

// CreateDocument creates a new document in the specified collection.
CreateDocument(ctx context.Context, dbName, collectionName string, document any) (string, error)
// GetDocument retrieves a document by its ID from the specified collection.
Expand Down
46 changes: 44 additions & 2 deletions pkg/gofr/container/datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,28 @@ type ScyllaDBProvider interface {
}

type ArangoDB interface {
// CreateDB creates a new database in ArangoDB.
CreateDB(ctx context.Context, database string) error
// DropDB deletes an existing database in ArangoDB.
DropDB(ctx context.Context, database string) error

// CreateCollection creates a new collection in a database with specified type.
CreateCollection(ctx context.Context, database, collection string, isEdge bool) error
// DropCollection deletes an existing collection from a database.
DropCollection(ctx context.Context, database, collection string) error

// CreateGraph creates a new graph in a database.
// Parameters:
// - ctx: Request context for tracing and cancellation.
// - database: Name of the database where the graph will be created.
// - graph: Name of the graph to be created.
// - edgeDefinitions: Pointer to EdgeDefinition struct containing edge definitions.
//
// Returns an error if the edgeDefinitions parameter is not of type *EdgeDefinition or is nil.
CreateGraph(ctx context.Context, database, graph string, edgeDefinitions any) error
// DropGraph deletes an existing graph from a database.
DropGraph(ctx context.Context, database, graph string) error

// CreateDocument creates a new document in the specified collection.
CreateDocument(ctx context.Context, dbName, collectionName string, document any) (string, error)
// GetDocument retrieves a document by its ID from the specified collection.
Expand All @@ -585,10 +607,30 @@ type ArangoDB interface {
// DeleteDocument deletes a document by its ID from the specified collection.
DeleteDocument(ctx context.Context, dbName, collectionName, documentID string) error

// GetEdges retrieves all the edge documents connected to a specific vertex in an ArangoDB graph.
// GetEdges fetches all edges connected to a given vertex in the specified edge collection.
//
// Parameters:
// - ctx: Request context for tracing and cancellation.
// - dbName: Database name.
// - graphName: Graph name.
// - edgeCollection: Edge collection name.
// - vertexID: Full vertex ID (e.g., "persons/16563").
// - resp: Pointer to `*EdgeDetails` to store results.
//
// Returns an error if input is invalid, `resp` is of the wrong type, or the query fails.
GetEdges(ctx context.Context, dbName, graphName, edgeCollection, vertexID string, resp any) error

// Query executes an AQL query and binds the results
// Query executes an AQL query and binds the results.
//
// Parameters:
// - ctx: Request context for tracing and cancellation.
// - dbName: Name of the database where the query will be executed.
// - query: AQL query string to be executed.
// - bindVars: Map of bind variables to be used in the query.
// - result: Pointer to a slice of maps where the query results will be stored.
//
// Returns an error if the database connection fails, the query execution fails, or
// the result parameter is not a pointer to a slice of maps.
Query(ctx context.Context, dbName string, query string, bindVars map[string]any, result any) error

HealthChecker
Expand Down
2 changes: 2 additions & 0 deletions pkg/gofr/container/mock_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Mocks struct {
Mongo *MockMongo
KVStore *MockKVStore
DGraph *MockDgraph
ArangoDB *MockArangoDBProvider
OpenTSDB *MockOpenTSDBProvider
File *file.MockFileSystemProvider
HTTPService *service.MockHTTP
Expand Down Expand Up @@ -119,6 +120,7 @@ func NewMockContainer(t *testing.T, options ...options) (*Container, *Mocks) {
HTTPService: httpMock,
DGraph: dgraphMock,
OpenTSDB: opentsdbMock,
ArangoDB: arangoMock,
Metrics: mockMetrics,
}

Expand Down
168 changes: 168 additions & 0 deletions pkg/gofr/container/mock_datasources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pkg/gofr/datasource/arangodb/arango.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Client struct {
tracer trace.Tracer
config *Config
endpoint string
*DB
*Document
*Graph
}
Expand Down Expand Up @@ -59,6 +60,7 @@ func New(c Config) *Client {
config: &c,
}

client.DB = &DB{client: client}
client.Document = &Document{client: client}
client.Graph = &Graph{client: client}

Expand Down Expand Up @@ -149,6 +151,16 @@ func (c *Client) validateConfig() error {
}

// Query executes an AQL query and binds the results.
//
// Parameters:
// - ctx: Request context for tracing and cancellation.
// - dbName: Name of the database where the query will be executed.
// - query: AQL query string to be executed.
// - bindVars: Map of bind variables to be used in the query.
// - result: Pointer to a slice of maps where the query results will be stored.
//
// Returns an error if the database connection fails, the query execution fails, or the
// result parameter is not a pointer to a slice of maps.
func (c *Client) Query(ctx context.Context, dbName, query string, bindVars map[string]any, result any) error {
tracerCtx, span := c.addTrace(ctx, "query", map[string]string{"DB": dbName})
startTime := time.Now()
Expand Down
Loading

0 comments on commit 2bcdc8e

Please sign in to comment.