Skip to content

Commit 1efa69f

Browse files
committed
move v2 APIs from v1 APIs
TODO: 1. Update README 2. Update Open funcion to take ns in the URL 3. Tests should to pass
1 parent 3d8e767 commit 1efa69f

19 files changed

+1861
-3381
lines changed

.trunk/trunk.yaml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
version: 0.1
44

55
cli:
6-
version: 1.22.12
6+
version: 1.25.0
77

88
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
99
plugins:
1010
sources:
1111
- id: trunk
12-
ref: v1.6.8
12+
ref: v1.7.2
1313
uri: https://github.com/trunk-io/plugins
1414

1515
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
1616
runtimes:
1717
enabled:
1818
19-
- node@18.20.5
19+
- node@22.16.0
2020
2121

2222
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
@@ -27,18 +27,19 @@ lint:
2727
- protos/api/*.pb.go
2828
- protos/api.v2/*.pb.go
2929
enabled:
30-
31-
30+
31+
32+
3233
33-
34+
3435
- git-diff-check
3536
3637
37-
- markdownlint@0.44.0
38-
- osv-scanner@2.0.1
39-
- prettier@3.5.3
40-
- trufflehog@3.88.24
41-
38+
- markdownlint@0.45.0
39+
- osv-scanner@2.2.2
40+
- prettier@3.6.2
41+
- trufflehog@3.90.5
42+
4243
actions:
4344
enabled:
4445
- trunk-announce

alter.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* SPDX-FileCopyrightText: © Hypermode Inc. <[email protected]>
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package dgo
7+
8+
import (
9+
"context"
10+
11+
"github.com/dgraph-io/dgo/v250/protos/api"
12+
)
13+
14+
func (d *Dgraph) DropAll(ctx context.Context) error {
15+
req := &api.Operation{DropAll: true}
16+
return d.doAlter(ctx, req)
17+
}
18+
19+
func (d *Dgraph) DropData(ctx context.Context) error {
20+
req := &api.Operation{DropOp: api.Operation_DATA}
21+
return d.doAlter(ctx, req)
22+
}
23+
24+
func (d *Dgraph) DropPredicate(ctx context.Context, predicate string) error {
25+
req := &api.Operation{DropOp: api.Operation_ATTR, DropValue: predicate}
26+
return d.doAlter(ctx, req)
27+
}
28+
29+
func (d *Dgraph) DropType(ctx context.Context, typeName string) error {
30+
req := &api.Operation{DropOp: api.Operation_TYPE, DropValue: typeName}
31+
return d.doAlter(ctx, req)
32+
}
33+
34+
func (d *Dgraph) SetSchema(ctx context.Context, schema string) error {
35+
req := &api.Operation{Schema: schema}
36+
return d.doAlter(ctx, req)
37+
}
38+
39+
func (d *Dgraph) doAlter(ctx context.Context, req *api.Operation) error {
40+
_, err := doWithRetryLogin(ctx, d, func(dc api.DgraphClient) (*api.Payload, error) {
41+
return dc.Alter(d.getContext(ctx), req)
42+
})
43+
return err
44+
}

alterv2.go

Lines changed: 0 additions & 67 deletions
This file was deleted.

client.go

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"google.golang.org/protobuf/proto"
2424

2525
"github.com/dgraph-io/dgo/v250/protos/api"
26-
apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2"
2726
)
2827

2928
const (
@@ -33,14 +32,10 @@ const (
3332

3433
// Dgraph is a transaction-aware client to a Dgraph cluster.
3534
type Dgraph struct {
36-
useV1 bool
37-
3835
jwtMutex sync.RWMutex
3936
jwt api.Jwt
40-
41-
conns []*grpc.ClientConn
42-
dc []api.DgraphClient
43-
dcv2 []apiv2.DgraphClient
37+
conns []*grpc.ClientConn
38+
dc []api.DgraphClient
4439
}
4540

4641
type authCreds struct {
@@ -65,18 +60,7 @@ func (a *authCreds) RequireTransportSecurity() bool {
6560
//
6661
// Deprecated: Use dgo.NewClient or dgo.Open instead.
6762
func NewDgraphClient(clients ...api.DgraphClient) *Dgraph {
68-
dcv2 := make([]apiv2.DgraphClient, len(clients))
69-
for i, client := range clients {
70-
dcv2[i] = apiv2.NewDgraphClient(api.GetConn(client))
71-
}
72-
73-
d := &Dgraph{useV1: true, dc: clients, dcv2: dcv2}
74-
75-
// we ignore the error here, because there is not much we can do about
76-
// the error. We want to make best effort to figure out what API to use.
77-
_ = d.ping()
78-
79-
return d
63+
return &Dgraph{dc: clients}
8064
}
8165

8266
// DialCloud creates a new TLS connection to a Dgraph Cloud backend
@@ -175,8 +159,6 @@ func (d *Dgraph) LoginIntoNamespace(ctx context.Context,
175159
// 1. Modify the schema.
176160
// 2. Drop a predicate.
177161
// 3. Drop the database.
178-
//
179-
// Deprecated: use DropAllNamespaces, DropAll, DropData, DropPredicate, DropType, SetSchema instead.
180162
func (d *Dgraph) Alter(ctx context.Context, op *api.Operation) error {
181163
dc := d.anyClient()
182164
_, err := dc.Alter(d.getContext(ctx), op)

0 commit comments

Comments
 (0)