Skip to content

Commit d4ee5b0

Browse files
authored
OAS-10042 Support for missing dirty read options (query, transaction apis). Get inbound and outbound edges. (#621)
1 parent 9127562 commit d4ee5b0

16 files changed

+330
-113
lines changed

v2/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## [master](https://github.com/arangodb/go-driver/tree/master) (N/A)
44
- Improve backup tests stability
55
- CheckAvailability function for the specific member
6+
- Switch to Go 1.22.6
7+
- Support for missing dirty read options (query, transaction apis)
8+
- Get inbound and outbound edges
69

710
## [2.1.0](https://github.com/arangodb/go-driver/tree/v2.1.0) (2024-04-02)
811
- Switch to Go 1.21.5

v2/arangodb/collection_documents_create.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2020-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -171,51 +171,51 @@ func (c *CollectionDocumentCreateOptions) modifyRequest(r connection.Request) er
171171
}
172172

173173
if c.WithWaitForSync != nil {
174-
r.AddQuery("waitForSync", boolToString(*c.WithWaitForSync))
174+
r.AddQuery(QueryWaitForSync, boolToString(*c.WithWaitForSync))
175175
}
176176

177177
if c.Overwrite != nil {
178-
r.AddQuery("overwrite", boolToString(*c.Overwrite))
178+
r.AddQuery(QueryOverwrite, boolToString(*c.Overwrite))
179179
}
180180

181181
if c.OverwriteMode != nil {
182-
r.AddQuery("overwriteMode", c.OverwriteMode.String())
182+
r.AddQuery(QueryOverwriteMode, c.OverwriteMode.String())
183183
}
184184

185185
if c.Silent != nil {
186-
r.AddQuery("silent", boolToString(*c.Silent))
186+
r.AddQuery(QuerySilent, boolToString(*c.Silent))
187187
}
188188

189189
if c.NewObject != nil {
190-
r.AddQuery("returnNew", "true")
190+
r.AddQuery(QueryReturnNew, "true")
191191
}
192192

193193
if c.OldObject != nil {
194-
r.AddQuery("returnOld", "true")
194+
r.AddQuery(QueryReturnOld, "true")
195195
}
196196

197197
if c.RefillIndexCaches != nil {
198-
r.AddQuery("refillIndexCaches", boolToString(*c.RefillIndexCaches))
198+
r.AddQuery(QueryRefillIndexCaches, boolToString(*c.RefillIndexCaches))
199199
}
200200

201201
if c.KeepNull != nil {
202-
r.AddQuery("keepNull", boolToString(*c.KeepNull))
202+
r.AddQuery(QueryKeepNull, boolToString(*c.KeepNull))
203203
}
204204

205205
if c.MergeObjects != nil {
206-
r.AddQuery("mergeObjects", boolToString(*c.MergeObjects))
206+
r.AddQuery(QueryMergeObjects, boolToString(*c.MergeObjects))
207207
}
208208

209209
if c.IgnoreRevs != nil {
210-
r.AddQuery("ignoreRevs", boolToString(*c.IgnoreRevs))
210+
r.AddQuery(QueryIgnoreRevs, boolToString(*c.IgnoreRevs))
211211
}
212212

213213
if c.IsRestore != nil {
214-
r.AddQuery("isRestore", boolToString(*c.IsRestore))
214+
r.AddQuery(QueryIsRestore, boolToString(*c.IsRestore))
215215
}
216216

217217
if c.VersionAttribute != "" {
218-
r.AddQuery("versionAttribute", c.VersionAttribute)
218+
r.AddQuery(QueryVersionAttribute, c.VersionAttribute)
219219
}
220220

221221
return nil

v2/arangodb/collection_documents_delete.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -95,27 +95,27 @@ func (c *CollectionDocumentDeleteOptions) modifyRequest(r connection.Request) er
9595
}
9696

9797
if c.IfMatch != "" {
98-
r.AddHeader("If-Match", c.IfMatch)
98+
r.AddHeader(HeaderIfMatch, c.IfMatch)
9999
}
100100

101101
if c.IgnoreRevs != nil {
102-
r.AddQuery("ignoreRevs", boolToString(*c.IgnoreRevs))
102+
r.AddQuery(QueryIgnoreRevs, boolToString(*c.IgnoreRevs))
103103
}
104104

105105
if c.WithWaitForSync != nil {
106-
r.AddQuery("waitForSync", boolToString(*c.WithWaitForSync))
106+
r.AddQuery(QueryWaitForSync, boolToString(*c.WithWaitForSync))
107107
}
108108

109109
if c.OldObject != nil {
110-
r.AddQuery("returnOld", "true")
110+
r.AddQuery(QueryReturnOld, "true")
111111
}
112112

113113
if c.Silent != nil {
114-
r.AddQuery("silent", boolToString(*c.Silent))
114+
r.AddQuery(QuerySilent, boolToString(*c.Silent))
115115
}
116116

117117
if c.RefillIndexCaches != nil {
118-
r.AddQuery("refillIndexCaches", boolToString(*c.RefillIndexCaches))
118+
r.AddQuery(QueryRefillIndexCaches, boolToString(*c.RefillIndexCaches))
119119
}
120120

121121
return nil

v2/arangodb/collection_documents_read.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2020-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -99,23 +99,23 @@ func (c *CollectionDocumentReadOptions) modifyRequest(r connection.Request) erro
9999
}
100100

101101
if c.IfMatch != "" {
102-
r.AddHeader("If-Match", c.IfMatch)
102+
r.AddHeader(HeaderIfMatch, c.IfMatch)
103103
}
104104

105105
if c.IfNoneMatch != "" {
106-
r.AddHeader("If-None-Match", c.IfNoneMatch)
106+
r.AddHeader(HeaderIfNoneMatch, c.IfNoneMatch)
107107
}
108108

109109
if c.IgnoreRevs != nil {
110-
r.AddQuery("ignoreRevs", boolToString(*c.IgnoreRevs))
110+
r.AddQuery(QueryIgnoreRevs, boolToString(*c.IgnoreRevs))
111111
}
112112

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

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

121121
return nil

v2/arangodb/collection_documents_replace.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,39 +111,39 @@ func (c *CollectionDocumentReplaceOptions) modifyRequest(r connection.Request) e
111111
}
112112

113113
if c.IfMatch != "" {
114-
r.AddHeader("If-Match", c.IfMatch)
114+
r.AddHeader(HeaderIfMatch, c.IfMatch)
115115
}
116116

117117
if c.WithWaitForSync != nil {
118-
r.AddQuery("waitForSync", boolToString(*c.WithWaitForSync))
118+
r.AddQuery(QueryWaitForSync, boolToString(*c.WithWaitForSync))
119119
}
120120

121121
if c.Silent != nil {
122-
r.AddQuery("silent", boolToString(*c.Silent))
122+
r.AddQuery(QuerySilent, boolToString(*c.Silent))
123123
}
124124

125125
if c.NewObject != nil {
126-
r.AddQuery("returnNew", "true")
126+
r.AddQuery(QueryReturnNew, "true")
127127
}
128128

129129
if c.OldObject != nil {
130-
r.AddQuery("returnOld", "true")
130+
r.AddQuery(QueryReturnOld, "true")
131131
}
132132

133133
if c.RefillIndexCaches != nil {
134-
r.AddQuery("refillIndexCaches", boolToString(*c.RefillIndexCaches))
134+
r.AddQuery(QueryRefillIndexCaches, boolToString(*c.RefillIndexCaches))
135135
}
136136

137137
if c.IgnoreRevs != nil {
138-
r.AddQuery("ignoreRevs", boolToString(*c.IgnoreRevs))
138+
r.AddQuery(QueryIgnoreRevs, boolToString(*c.IgnoreRevs))
139139
}
140140

141141
if c.IsRestore != nil {
142-
r.AddQuery("isRestore", boolToString(*c.IsRestore))
142+
r.AddQuery(QueryIsRestore, boolToString(*c.IsRestore))
143143
}
144144

145145
if c.VersionAttribute != "" {
146-
r.AddQuery("versionAttribute", c.VersionAttribute)
146+
r.AddQuery(QueryVersionAttribute, c.VersionAttribute)
147147
}
148148

149149
return nil

v2/arangodb/collection_documents_update.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2020-2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2020-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -119,43 +119,43 @@ func (c *CollectionDocumentUpdateOptions) modifyRequest(r connection.Request) er
119119
}
120120

121121
if c.IfMatch != "" {
122-
r.AddHeader("If-Match", c.IfMatch)
122+
r.AddHeader(HeaderIfMatch, c.IfMatch)
123123
}
124124

125125
if c.WithWaitForSync != nil {
126-
r.AddQuery("waitForSync", boolToString(*c.WithWaitForSync))
126+
r.AddQuery(QueryWaitForSync, boolToString(*c.WithWaitForSync))
127127
}
128128

129129
if c.Silent != nil {
130-
r.AddQuery("silent", boolToString(*c.Silent))
130+
r.AddQuery(QuerySilent, boolToString(*c.Silent))
131131
}
132132

133133
if c.NewObject != nil {
134-
r.AddQuery("returnNew", "true")
134+
r.AddQuery(QueryReturnNew, "true")
135135
}
136136

137137
if c.OldObject != nil {
138-
r.AddQuery("returnOld", "true")
138+
r.AddQuery(QueryReturnOld, "true")
139139
}
140140

141141
if c.RefillIndexCaches != nil {
142-
r.AddQuery("refillIndexCaches", boolToString(*c.RefillIndexCaches))
142+
r.AddQuery(QueryRefillIndexCaches, boolToString(*c.RefillIndexCaches))
143143
}
144144

145145
if c.KeepNull != nil {
146-
r.AddQuery("keepNull", boolToString(*c.KeepNull))
146+
r.AddQuery(QueryKeepNull, boolToString(*c.KeepNull))
147147
}
148148

149149
if c.MergeObjects != nil {
150-
r.AddQuery("mergeObjects", boolToString(*c.MergeObjects))
150+
r.AddQuery(QueryMergeObjects, boolToString(*c.MergeObjects))
151151
}
152152

153153
if c.IgnoreRevs != nil {
154-
r.AddQuery("ignoreRevs", boolToString(*c.IgnoreRevs))
154+
r.AddQuery(QueryIgnoreRevs, boolToString(*c.IgnoreRevs))
155155
}
156156

157157
if c.VersionAttribute != "" {
158-
r.AddQuery("versionAttribute", c.VersionAttribute)
158+
r.AddQuery(QueryVersionAttribute, c.VersionAttribute)
159159
}
160160

161161
return nil

v2/arangodb/database_graph.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,32 @@
2020

2121
package arangodb
2222

23-
import "context"
23+
import (
24+
"context"
25+
26+
"github.com/arangodb/go-driver/v2/connection"
27+
)
2428

2529
const (
2630
// SatelliteGraph is a special replication factor for satellite graphs.
2731
// Use this replication factor to create a satellite graph.
2832
SatelliteGraph = -100
2933
)
3034

35+
type EdgeDirection string
36+
37+
const (
38+
// EdgeDirectionIn selects inbound edges
39+
EdgeDirectionIn EdgeDirection = "in"
40+
// EdgeDirectionOut selects outbound edges
41+
EdgeDirectionOut EdgeDirection = "out"
42+
)
43+
3144
type DatabaseGraph interface {
45+
// GetEdges returns inbound and outbound edge documents of a given vertex.
46+
// Requires Edge collection name and vertex ID
47+
GetEdges(ctx context.Context, name, vertex string, options *GetEdgesOptions) ([]EdgeDetails, error)
48+
3249
// Graph opens a connection to an existing graph within the database.
3350
// If no graph with given name exists, an NotFoundError is returned.
3451
Graph(ctx context.Context, name string, options *GetGraphOptions) (Graph, error)
@@ -44,6 +61,22 @@ type DatabaseGraph interface {
4461
CreateGraph(ctx context.Context, name string, graph *GraphDefinition, options *CreateGraphOptions) (Graph, error)
4562
}
4663

64+
type GetEdgesOptions struct {
65+
// The direction of the edges. Allowed values are "in" and "out". If not set, edges in both directions are returned.
66+
Direction EdgeDirection `json:"direction,omitempty"`
67+
68+
// Set this to true to allow the Coordinator to ask any shard replica for the data, not only the shard leader.
69+
// This may result in “dirty reads”.
70+
AllowDirtyReads *bool `json:"-"`
71+
}
72+
73+
type EdgeDetails struct {
74+
DocumentMeta
75+
From string `json:"_from"`
76+
To string `json:"_to"`
77+
Label string `json:"$label"`
78+
}
79+
4780
type GetGraphOptions struct {
4881
// SkipExistCheck skips checking if graph exists
4982
SkipExistCheck bool `json:"skipExistCheck,omitempty"`
@@ -60,3 +93,19 @@ type GraphsResponseReader interface {
6093
// Read returns next Graph. If no Graph left, shared.NoMoreDocumentsError returned
6194
Read() (Graph, error)
6295
}
96+
97+
func (q *GetEdgesOptions) modifyRequest(r connection.Request) error {
98+
if q == nil {
99+
return nil
100+
}
101+
102+
if q.AllowDirtyReads != nil {
103+
r.AddHeader(HeaderDirtyReads, boolToString(*q.AllowDirtyReads))
104+
}
105+
106+
if q.Direction != "" {
107+
r.AddQuery(QueryDirection, string(q.Direction))
108+
}
109+
110+
return nil
111+
}

v2/arangodb/database_graph_impl.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@ type databaseGraph struct {
4444
db *database
4545
}
4646

47+
func (d *databaseGraph) GetEdges(ctx context.Context, name, vertex string, options *GetEdgesOptions) ([]EdgeDetails, error) {
48+
if name == "" || vertex == "" {
49+
return nil, errors.WithStack(errors.New("edge collection name and vertex must be set"))
50+
}
51+
52+
urlEndpoint := d.db.url("_api", "edges", url.PathEscape(name))
53+
54+
var response struct {
55+
shared.ResponseStruct `json:",inline"`
56+
Edges []EdgeDetails `json:"edges,omitempty"`
57+
}
58+
59+
resp, err := connection.CallGet(ctx, d.db.connection(), urlEndpoint, &response, append(d.db.modifiers, options.modifyRequest, connection.WithQuery("vertex", vertex))...)
60+
if err != nil {
61+
return nil, errors.WithStack(err)
62+
}
63+
64+
switch code := resp.Code(); code {
65+
case http.StatusOK:
66+
return response.Edges, nil
67+
default:
68+
return nil, response.AsArangoErrorWithCode(code)
69+
}
70+
}
71+
4772
func (d *databaseGraph) Graph(ctx context.Context, name string, options *GetGraphOptions) (Graph, error) {
4873
urlEndpoint := d.db.url("_api", "gharial", url.PathEscape(name))
4974

0 commit comments

Comments
 (0)