Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## [master](https://github.com/arangodb/go-driver/tree/master) (N/A)
- Improve backup tests stability
- CheckAvailability function for the specific member
- Switch to Go 1.22.6
- Support for missing dirty read options (query, transaction apis)
- Get inbound and outbound edges

## [2.1.0](https://github.com/arangodb/go-driver/tree/v2.1.0) (2024-04-02)
- Switch to Go 1.21.5
Expand Down
26 changes: 13 additions & 13 deletions v2/arangodb/collection_documents_create.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2020-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -171,51 +171,51 @@ func (c *CollectionDocumentCreateOptions) modifyRequest(r connection.Request) er
}

if c.WithWaitForSync != nil {
r.AddQuery("waitForSync", boolToString(*c.WithWaitForSync))
r.AddQuery(QueryWaitForSync, boolToString(*c.WithWaitForSync))
}

if c.Overwrite != nil {
r.AddQuery("overwrite", boolToString(*c.Overwrite))
r.AddQuery(QueryOverwrite, boolToString(*c.Overwrite))
}

if c.OverwriteMode != nil {
r.AddQuery("overwriteMode", c.OverwriteMode.String())
r.AddQuery(QueryOverwriteMode, c.OverwriteMode.String())
}

if c.Silent != nil {
r.AddQuery("silent", boolToString(*c.Silent))
r.AddQuery(QuerySilent, boolToString(*c.Silent))
}

if c.NewObject != nil {
r.AddQuery("returnNew", "true")
r.AddQuery(QueryReturnNew, "true")
}

if c.OldObject != nil {
r.AddQuery("returnOld", "true")
r.AddQuery(QueryReturnOld, "true")
}

if c.RefillIndexCaches != nil {
r.AddQuery("refillIndexCaches", boolToString(*c.RefillIndexCaches))
r.AddQuery(QueryRefillIndexCaches, boolToString(*c.RefillIndexCaches))
}

if c.KeepNull != nil {
r.AddQuery("keepNull", boolToString(*c.KeepNull))
r.AddQuery(QueryKeepNull, boolToString(*c.KeepNull))
}

if c.MergeObjects != nil {
r.AddQuery("mergeObjects", boolToString(*c.MergeObjects))
r.AddQuery(QueryMergeObjects, boolToString(*c.MergeObjects))
}

if c.IgnoreRevs != nil {
r.AddQuery("ignoreRevs", boolToString(*c.IgnoreRevs))
r.AddQuery(QueryIgnoreRevs, boolToString(*c.IgnoreRevs))
}

if c.IsRestore != nil {
r.AddQuery("isRestore", boolToString(*c.IsRestore))
r.AddQuery(QueryIsRestore, boolToString(*c.IsRestore))
}

if c.VersionAttribute != "" {
r.AddQuery("versionAttribute", c.VersionAttribute)
r.AddQuery(QueryVersionAttribute, c.VersionAttribute)
}

return nil
Expand Down
14 changes: 7 additions & 7 deletions v2/arangodb/collection_documents_delete.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -95,27 +95,27 @@ func (c *CollectionDocumentDeleteOptions) modifyRequest(r connection.Request) er
}

if c.IfMatch != "" {
r.AddHeader("If-Match", c.IfMatch)
r.AddHeader(HeaderIfMatch, c.IfMatch)
}

if c.IgnoreRevs != nil {
r.AddQuery("ignoreRevs", boolToString(*c.IgnoreRevs))
r.AddQuery(QueryIgnoreRevs, boolToString(*c.IgnoreRevs))
}

if c.WithWaitForSync != nil {
r.AddQuery("waitForSync", boolToString(*c.WithWaitForSync))
r.AddQuery(QueryWaitForSync, boolToString(*c.WithWaitForSync))
}

if c.OldObject != nil {
r.AddQuery("returnOld", "true")
r.AddQuery(QueryReturnOld, "true")
}

if c.Silent != nil {
r.AddQuery("silent", boolToString(*c.Silent))
r.AddQuery(QuerySilent, boolToString(*c.Silent))
}

if c.RefillIndexCaches != nil {
r.AddQuery("refillIndexCaches", boolToString(*c.RefillIndexCaches))
r.AddQuery(QueryRefillIndexCaches, boolToString(*c.RefillIndexCaches))
}

return nil
Expand Down
12 changes: 6 additions & 6 deletions v2/arangodb/collection_documents_read.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2020-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -99,23 +99,23 @@ func (c *CollectionDocumentReadOptions) modifyRequest(r connection.Request) erro
}

if c.IfMatch != "" {
r.AddHeader("If-Match", c.IfMatch)
r.AddHeader(HeaderIfMatch, c.IfMatch)
}

if c.IfNoneMatch != "" {
r.AddHeader("If-None-Match", c.IfNoneMatch)
r.AddHeader(HeaderIfNoneMatch, c.IfNoneMatch)
}

if c.IgnoreRevs != nil {
r.AddQuery("ignoreRevs", boolToString(*c.IgnoreRevs))
r.AddQuery(QueryIgnoreRevs, boolToString(*c.IgnoreRevs))
}

if c.AllowDirtyReads != nil {
r.AddHeader("x-arango-allow-dirty-read", boolToString(*c.AllowDirtyReads))
r.AddHeader(HeaderDirtyReads, boolToString(*c.AllowDirtyReads))
}

if c.TransactionID != "" {
r.AddHeader("x-arango-trx-id", c.TransactionID)
r.AddHeader(HeaderTransaction, c.TransactionID)
}

return nil
Expand Down
18 changes: 9 additions & 9 deletions v2/arangodb/collection_documents_replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,39 +111,39 @@ func (c *CollectionDocumentReplaceOptions) modifyRequest(r connection.Request) e
}

if c.IfMatch != "" {
r.AddHeader("If-Match", c.IfMatch)
r.AddHeader(HeaderIfMatch, c.IfMatch)
}

if c.WithWaitForSync != nil {
r.AddQuery("waitForSync", boolToString(*c.WithWaitForSync))
r.AddQuery(QueryWaitForSync, boolToString(*c.WithWaitForSync))
}

if c.Silent != nil {
r.AddQuery("silent", boolToString(*c.Silent))
r.AddQuery(QuerySilent, boolToString(*c.Silent))
}

if c.NewObject != nil {
r.AddQuery("returnNew", "true")
r.AddQuery(QueryReturnNew, "true")
}

if c.OldObject != nil {
r.AddQuery("returnOld", "true")
r.AddQuery(QueryReturnOld, "true")
}

if c.RefillIndexCaches != nil {
r.AddQuery("refillIndexCaches", boolToString(*c.RefillIndexCaches))
r.AddQuery(QueryRefillIndexCaches, boolToString(*c.RefillIndexCaches))
}

if c.IgnoreRevs != nil {
r.AddQuery("ignoreRevs", boolToString(*c.IgnoreRevs))
r.AddQuery(QueryIgnoreRevs, boolToString(*c.IgnoreRevs))
}

if c.IsRestore != nil {
r.AddQuery("isRestore", boolToString(*c.IsRestore))
r.AddQuery(QueryIsRestore, boolToString(*c.IsRestore))
}

if c.VersionAttribute != "" {
r.AddQuery("versionAttribute", c.VersionAttribute)
r.AddQuery(QueryVersionAttribute, c.VersionAttribute)
}

return nil
Expand Down
22 changes: 11 additions & 11 deletions v2/arangodb/collection_documents_update.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2020-2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -119,43 +119,43 @@ func (c *CollectionDocumentUpdateOptions) modifyRequest(r connection.Request) er
}

if c.IfMatch != "" {
r.AddHeader("If-Match", c.IfMatch)
r.AddHeader(HeaderIfMatch, c.IfMatch)
}

if c.WithWaitForSync != nil {
r.AddQuery("waitForSync", boolToString(*c.WithWaitForSync))
r.AddQuery(QueryWaitForSync, boolToString(*c.WithWaitForSync))
}

if c.Silent != nil {
r.AddQuery("silent", boolToString(*c.Silent))
r.AddQuery(QuerySilent, boolToString(*c.Silent))
}

if c.NewObject != nil {
r.AddQuery("returnNew", "true")
r.AddQuery(QueryReturnNew, "true")
}

if c.OldObject != nil {
r.AddQuery("returnOld", "true")
r.AddQuery(QueryReturnOld, "true")
}

if c.RefillIndexCaches != nil {
r.AddQuery("refillIndexCaches", boolToString(*c.RefillIndexCaches))
r.AddQuery(QueryRefillIndexCaches, boolToString(*c.RefillIndexCaches))
}

if c.KeepNull != nil {
r.AddQuery("keepNull", boolToString(*c.KeepNull))
r.AddQuery(QueryKeepNull, boolToString(*c.KeepNull))
}

if c.MergeObjects != nil {
r.AddQuery("mergeObjects", boolToString(*c.MergeObjects))
r.AddQuery(QueryMergeObjects, boolToString(*c.MergeObjects))
}

if c.IgnoreRevs != nil {
r.AddQuery("ignoreRevs", boolToString(*c.IgnoreRevs))
r.AddQuery(QueryIgnoreRevs, boolToString(*c.IgnoreRevs))
}

if c.VersionAttribute != "" {
r.AddQuery("versionAttribute", c.VersionAttribute)
r.AddQuery(QueryVersionAttribute, c.VersionAttribute)
}

return nil
Expand Down
51 changes: 50 additions & 1 deletion v2/arangodb/database_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,32 @@

package arangodb

import "context"
import (
"context"

"github.com/arangodb/go-driver/v2/connection"
)

const (
// SatelliteGraph is a special replication factor for satellite graphs.
// Use this replication factor to create a satellite graph.
SatelliteGraph = -100
)

type EdgeDirection string

const (
// EdgeDirectionIn selects inbound edges
EdgeDirectionIn EdgeDirection = "in"
// EdgeDirectionOut selects outbound edges
EdgeDirectionOut EdgeDirection = "out"
)

type DatabaseGraph interface {
// GetEdges returns inbound and outbound edge documents of a given vertex.
// Requires Edge collection name and vertex ID
GetEdges(ctx context.Context, name, vertex string, options *GetEdgesOptions) ([]EdgeDetails, error)

// Graph opens a connection to an existing graph within the database.
// If no graph with given name exists, an NotFoundError is returned.
Graph(ctx context.Context, name string, options *GetGraphOptions) (Graph, error)
Expand All @@ -44,6 +61,22 @@ type DatabaseGraph interface {
CreateGraph(ctx context.Context, name string, graph *GraphDefinition, options *CreateGraphOptions) (Graph, error)
}

type GetEdgesOptions struct {
// The direction of the edges. Allowed values are "in" and "out". If not set, edges in both directions are returned.
Direction EdgeDirection `json:"direction,omitempty"`

// Set this to true to allow the Coordinator to ask any shard replica for the data, not only the shard leader.
// This may result in “dirty reads”.
AllowDirtyReads *bool `json:"-"`
}

type EdgeDetails struct {
DocumentMeta
From string `json:"_from"`
To string `json:"_to"`
Label string `json:"$label"`
}

type GetGraphOptions struct {
// SkipExistCheck skips checking if graph exists
SkipExistCheck bool `json:"skipExistCheck,omitempty"`
Expand All @@ -60,3 +93,19 @@ type GraphsResponseReader interface {
// Read returns next Graph. If no Graph left, shared.NoMoreDocumentsError returned
Read() (Graph, error)
}

func (q *GetEdgesOptions) modifyRequest(r connection.Request) error {
if q == nil {
return nil
}

if q.AllowDirtyReads != nil {
r.AddHeader(HeaderDirtyReads, boolToString(*q.AllowDirtyReads))
}

if q.Direction != "" {
r.AddQuery(QueryDirection, string(q.Direction))
}

return nil
}
25 changes: 25 additions & 0 deletions v2/arangodb/database_graph_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ type databaseGraph struct {
db *database
}

func (d *databaseGraph) GetEdges(ctx context.Context, name, vertex string, options *GetEdgesOptions) ([]EdgeDetails, error) {
if name == "" || vertex == "" {
return nil, errors.WithStack(errors.New("edge collection name and vertex must be set"))
}

urlEndpoint := d.db.url("_api", "edges", url.PathEscape(name))

var response struct {
shared.ResponseStruct `json:",inline"`
Edges []EdgeDetails `json:"edges,omitempty"`
}

resp, err := connection.CallGet(ctx, d.db.connection(), urlEndpoint, &response, append(d.db.modifiers, options.modifyRequest, connection.WithQuery("vertex", vertex))...)
if err != nil {
return nil, errors.WithStack(err)
}

switch code := resp.Code(); code {
case http.StatusOK:
return response.Edges, nil
default:
return nil, response.AsArangoErrorWithCode(code)
}
}

func (d *databaseGraph) Graph(ctx context.Context, name string, options *GetGraphOptions) (Graph, error) {
urlEndpoint := d.db.url("_api", "gharial", url.PathEscape(name))

Expand Down
Loading