-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathalter.go
63 lines (54 loc) · 1.56 KB
/
alter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package dgo
import (
"context"
apiv25 "github.com/dgraph-io/dgo/v240/protos/api.v25"
)
func (d *Dgraph) DropAllNamespaces(ctx context.Context) error {
req := &apiv25.AlterRequest{Op: apiv25.AlterOp_DROP_ALL}
return d.doAlter(ctx, req)
}
func (d *Dgraph) DropAll(ctx context.Context, nsName string) error {
req := &apiv25.AlterRequest{
Op: apiv25.AlterOp_DROP_ALL_IN_NS,
NsName: nsName,
}
return d.doAlter(ctx, req)
}
func (d *Dgraph) DropData(ctx context.Context, nsName string) error {
req := &apiv25.AlterRequest{
Op: apiv25.AlterOp_DROP_DATA_IN_NS,
NsName: nsName,
}
return d.doAlter(ctx, req)
}
func (d *Dgraph) DropPredicate(ctx context.Context, nsName, predicate string) error {
req := &apiv25.AlterRequest{
Op: apiv25.AlterOp_DROP_PREDICATE_IN_NS,
NsName: nsName,
PredicateToDrop: predicate,
}
return d.doAlter(ctx, req)
}
func (d *Dgraph) DropType(ctx context.Context, nsName, typeName string) error {
req := &apiv25.AlterRequest{
Op: apiv25.AlterOp_DROP_TYPE_IN_NS,
NsName: nsName,
TypeToDrop: typeName,
}
return d.doAlter(ctx, req)
}
func (d *Dgraph) SetSchema(ctx context.Context, nsName string, schema string) error {
req := &apiv25.AlterRequest{
Op: apiv25.AlterOp_SCHEMA_IN_NS,
NsName: nsName,
Schema: schema,
}
return d.doAlter(ctx, req)
}
func (d *Dgraph) doAlter(ctx context.Context, req *apiv25.AlterRequest) error {
dc := d.anyClientv25()
_, err := doWithRetryLogin(ctx, d, func() (*apiv25.AlterResponse, error) {
return dc.Alter(d.getContext(ctx), req)
})
return err
}