Skip to content

Commit 37c9d26

Browse files
authored
Drivers 3.9: Hybrid SmartGraphs (TG-201) (#351)
1 parent 669f864 commit 37c9d26

File tree

6 files changed

+85
-0
lines changed

6 files changed

+85
-0
lines changed

database_graphs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ type CreateGraphOptions struct {
7070
WriteConcern int
7171
// IsDisjoint set isDisjoint flag for Graph. Required ArangoDB 3.7+
7272
IsDisjoint bool
73+
// Satellites contains an array of collection names that will be used to create SatelliteCollections for a Hybrid (Disjoint) SmartGraph (Enterprise Edition only)
74+
Satellites []string `json:"satellites"`
7375
}
7476

7577
// EdgeDefinition contains all information needed to define a single edge in a graph.
@@ -80,4 +82,6 @@ type EdgeDefinition struct {
8082
To []string `json:"to"`
8183
// From contains the names of one or more vertex collections that can contain source vertices.
8284
From []string `json:"from"`
85+
// Options contains optional parameters
86+
Options CreateEdgeCollectionOptions `json:"options,omitempty"`
8387
}

database_graphs_impl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ type createGraphAdditionalOptions struct {
166166
WriteConcern int `json:"writeConcern,omitempty"`
167167
// IsDisjoint set isDisjoint flag for Graph. Required ArangoDB 3.7+
168168
IsDisjoint bool `json:"isDisjoint,omitempty"`
169+
// Satellites contains an array of collection names that will be used to create SatelliteCollections for a Hybrid (Disjoint) SmartGraph (Enterprise Edition only)
170+
Satellites []string `json:"satellites"`
169171
}
170172

171173
// CreateGraph creates a new graph with given name and options, and opens a connection to it.
@@ -183,6 +185,7 @@ func (d *database) CreateGraph(ctx context.Context, name string, options *Create
183185
SmartGraphAttribute: options.SmartGraphAttribute,
184186
ReplicationFactor: graphReplicationFactor(options.ReplicationFactor),
185187
IsDisjoint: options.IsDisjoint,
188+
Satellites: options.Satellites,
186189
}
187190
} else if options.SmartGraphAttribute != "" || options.NumberOfShards != 0 {
188191
input.Options = &createGraphAdditionalOptions{
@@ -191,6 +194,7 @@ func (d *database) CreateGraph(ctx context.Context, name string, options *Create
191194
ReplicationFactor: graphReplicationFactor(options.ReplicationFactor),
192195
WriteConcern: options.WriteConcern,
193196
IsDisjoint: options.IsDisjoint,
197+
Satellites: options.Satellites,
194198
}
195199
}
196200
}

graph_edge_collections.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type GraphEdgeCollections interface {
4444
// constraints.To: contains the names of one or more edge collections that can contain target vertices.
4545
CreateEdgeCollection(ctx context.Context, collection string, constraints VertexConstraints) (Collection, error)
4646

47+
// CreateEdgeCollectionWithOptions creates an edge collection in the graph with additional options
48+
CreateEdgeCollectionWithOptions(ctx context.Context, collection string, constraints VertexConstraints, options CreateEdgeCollectionOptions) (Collection, error)
49+
4750
// SetVertexConstraints modifies the vertex constraints of an existing edge collection in the graph.
4851
SetVertexConstraints(ctx context.Context, collection string, constraints VertexConstraints) error
4952
}
@@ -55,3 +58,9 @@ type VertexConstraints struct {
5558
// To contains names of vertex collection that are allowed to be used in the To part of an edge.
5659
To []string
5760
}
61+
62+
// CreateEdgeCollectionOptions contains optional parameters for creating a new edge collection
63+
type CreateEdgeCollectionOptions struct {
64+
// Satellites contains an array of collection names that will be used to create SatelliteCollections for a Hybrid (Disjoint) SmartGraph (Enterprise Edition only)
65+
Satellites []string `json:"satellites"`
66+
}

graph_edge_collections_impl.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,35 @@ func (g *graph) CreateEdgeCollection(ctx context.Context, collection string, con
162162
return ec, nil
163163
}
164164

165+
// CreateEdgeCollectionWithOptions creates an edge collection in the graph with additional options
166+
func (g *graph) CreateEdgeCollectionWithOptions(ctx context.Context, collection string, constraints VertexConstraints, options CreateEdgeCollectionOptions) (Collection, error) {
167+
req, err := g.conn.NewRequest("POST", path.Join(g.relPath(), "edge"))
168+
if err != nil {
169+
return nil, WithStack(err)
170+
}
171+
input := EdgeDefinition{
172+
Collection: collection,
173+
From: constraints.From,
174+
To: constraints.To,
175+
Options: options,
176+
}
177+
if _, err := req.SetBody(input); err != nil {
178+
return nil, WithStack(err)
179+
}
180+
resp, err := g.conn.Do(ctx, req)
181+
if err != nil {
182+
return nil, WithStack(err)
183+
}
184+
if err := resp.CheckStatus(201, 202); err != nil {
185+
return nil, WithStack(err)
186+
}
187+
ec, err := newEdgeCollection(collection, g)
188+
if err != nil {
189+
return nil, WithStack(err)
190+
}
191+
return ec, nil
192+
}
193+
165194
// SetVertexConstraints modifies the vertex constraints of an existing edge collection in the graph.
166195
func (g *graph) SetVertexConstraints(ctx context.Context, collection string, constraints VertexConstraints) error {
167196
req, err := g.conn.NewRequest("PUT", path.Join(g.relPath(), "edge", collection))

graph_vertex_collections.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,13 @@ type GraphVertexCollections interface {
4141
// CreateVertexCollection creates a vertex collection in the graph.
4242
// collection: The name of the vertex collection to be used.
4343
CreateVertexCollection(ctx context.Context, collection string) (Collection, error)
44+
45+
// CreateVertexCollectionWithOptions creates a vertex collection in the graph
46+
CreateVertexCollectionWithOptions(ctx context.Context, collection string, options CreateVertexCollectionOptions) (Collection, error)
47+
}
48+
49+
// CreateVertexCollectionOptions contains optional parameters for creating a new vertex collection
50+
type CreateVertexCollectionOptions struct {
51+
// Satellites contains an array of collection names that will be used to create SatelliteCollections for a Hybrid (Disjoint) SmartGraph (Enterprise Edition only)
52+
Satellites []string `json:"satellites"`
4453
}

graph_vertex_collections_impl.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,33 @@ func (g *graph) CreateVertexCollection(ctx context.Context, collection string) (
143143
}
144144
return ec, nil
145145
}
146+
147+
// CreateVertexCollectionWithOptions creates a vertex collection in the graph
148+
func (g *graph) CreateVertexCollectionWithOptions(ctx context.Context, collection string, options CreateVertexCollectionOptions) (Collection, error) {
149+
req, err := g.conn.NewRequest("POST", path.Join(g.relPath(), "vertex"))
150+
if err != nil {
151+
return nil, WithStack(err)
152+
}
153+
input := struct {
154+
Collection string `json:"collection,omitempty"`
155+
Options CreateVertexCollectionOptions `json:"options,omitempty"`
156+
}{
157+
Collection: collection,
158+
Options: options,
159+
}
160+
if _, err := req.SetBody(input); err != nil {
161+
return nil, WithStack(err)
162+
}
163+
resp, err := g.conn.Do(ctx, req)
164+
if err != nil {
165+
return nil, WithStack(err)
166+
}
167+
if err := resp.CheckStatus(201, 202); err != nil {
168+
return nil, WithStack(err)
169+
}
170+
ec, err := newVertexCollection(collection, g)
171+
if err != nil {
172+
return nil, WithStack(err)
173+
}
174+
return ec, nil
175+
}

0 commit comments

Comments
 (0)