Skip to content

Commit a0500c8

Browse files
authored
Add DropCollections options to graph removal (#448)
1 parent fa19f30 commit a0500c8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

context.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const (
6767
keyOverwrite ContextKey = "arangodb-overwrite"
6868
keyUseQueueTimeout ContextKey = "arangodb-use-queue-timeout"
6969
keyMaxQueueTime ContextKey = "arangodb-max-queue-time-seconds"
70+
keyDropCollections ContextKey = "arangodb-drop-collections"
7071
keyDriverFlags ContextKey = "arangodb-driver-flags"
7172
)
7273

@@ -276,6 +277,16 @@ func WithOverwrite(parent context.Context) context.Context {
276277
return context.WithValue(contextOrBackground(parent), keyOverwrite, true)
277278
}
278279

280+
// WithDropCollections is used to configure a context to make graph removal functions to also drop the collections of the graph instead only the graph definition.
281+
// You can pass a single (optional) boolean. If that is set to true, you explicitly ask to also drop the collections of the graph.
282+
func WithDropCollections(parent context.Context, value ...bool) context.Context {
283+
v := true
284+
if len(value) == 1 {
285+
v = value[0]
286+
}
287+
return context.WithValue(contextOrBackground(parent), keyDropCollections, v)
288+
}
289+
279290
// WithDriverFlags is used to configure additional flags for the `x-arango-driver` header.
280291
func WithDriverFlags(parent context.Context, value []string) context.Context {
281292
return context.WithValue(contextOrBackground(parent), keyDriverFlags, value)
@@ -304,6 +315,7 @@ type contextSettings struct {
304315
Overwrite bool
305316
QueueTimeout bool
306317
MaxQueueTime time.Duration
318+
DropCollections *bool
307319
}
308320

309321
// loadContextResponseValue loads generic values from the response and puts it into variables specified
@@ -509,6 +521,13 @@ func applyContextSettings(ctx context.Context, req Request) contextSettings {
509521
result.OverwriteMode = mode
510522
}
511523
}
524+
// DropCollections
525+
if v := ctx.Value(keyDropCollections); v != nil {
526+
if dropCollections, ok := v.(bool); ok {
527+
req.SetQuery("dropCollections", strconv.FormatBool(dropCollections))
528+
result.DropCollections = &dropCollections
529+
}
530+
}
512531

513532
if v := ctx.Value(keyOverwrite); v != nil {
514533
if overwrite, ok := v.(bool); ok && overwrite {

graph_impl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func (g *graph) Remove(ctx context.Context) error {
126126
if err != nil {
127127
return WithStack(err)
128128
}
129+
applyContextSettings(ctx, req)
129130
resp, err := g.conn.Do(ctx, req)
130131
if err != nil {
131132
return WithStack(err)

0 commit comments

Comments
 (0)