@@ -10,7 +10,7 @@ import (
1010 "errors"
1111 "math/rand"
1212
13- apiv25 "github.com/dgraph-io/dgo/v250/protos/api.v25 "
13+ apiv2 "github.com/dgraph-io/dgo/v250/protos/api.v2 "
1414)
1515
1616const (
2424type txnOptions struct {
2525 readOnly bool
2626 bestEffort bool
27- respFormat apiv25 .RespFormat
27+ respFormat apiv2 .RespFormat
2828}
2929
3030// TxnOption is a function that modifies the txn options.
@@ -64,58 +64,58 @@ func buildTxnOptions(opts ...TxnOption) (*txnOptions, error) {
6464// RunDQL runs a DQL query in the given namespace. A DQL query could be a mutation
6565// or a query or an upsert which is a combination of mutations and queries.
6666func (d * Dgraph ) RunDQL (ctx context.Context , nsName string , q string , opts ... TxnOption ) (
67- * apiv25 .RunDQLResponse , error ) {
67+ * apiv2 .RunDQLResponse , error ) {
6868
6969 return d .RunDQLWithVars (ctx , nsName , q , nil , opts ... )
7070}
7171
7272// RunDQLWithVars is like RunDQL with variables.
7373func (d * Dgraph ) RunDQLWithVars (ctx context.Context , nsName string , q string ,
74- vars map [string ]string , opts ... TxnOption ) (* apiv25 .RunDQLResponse , error ) {
74+ vars map [string ]string , opts ... TxnOption ) (* apiv2 .RunDQLResponse , error ) {
7575
7676 topts , err := buildTxnOptions (opts ... )
7777 if err != nil {
7878 return nil , err
7979 }
8080
81- req := & apiv25 .RunDQLRequest {NsName : nsName , DqlQuery : q , Vars : vars ,
81+ req := & apiv2 .RunDQLRequest {NsName : nsName , DqlQuery : q , Vars : vars ,
8282 ReadOnly : topts .readOnly , BestEffort : topts .bestEffort , RespFormat : topts .respFormat }
83- return doWithRetryLogin (ctx , d , func (dc apiv25 .DgraphClient ) (* apiv25 .RunDQLResponse , error ) {
83+ return doWithRetryLogin (ctx , d , func (dc apiv2 .DgraphClient ) (* apiv2 .RunDQLResponse , error ) {
8484 return dc .RunDQL (d .getContext (ctx ), req )
8585 })
8686}
8787
8888// CreateNamespace creates a new namespace with the given name and password for groot user.
8989func (d * Dgraph ) CreateNamespace (ctx context.Context , name string ) error {
90- req := & apiv25 .CreateNamespaceRequest {NsName : name }
91- _ , err := doWithRetryLogin (ctx , d , func (dc apiv25 .DgraphClient ) (* apiv25 .CreateNamespaceResponse , error ) {
90+ req := & apiv2 .CreateNamespaceRequest {NsName : name }
91+ _ , err := doWithRetryLogin (ctx , d , func (dc apiv2 .DgraphClient ) (* apiv2 .CreateNamespaceResponse , error ) {
9292 return dc .CreateNamespace (d .getContext (ctx ), req )
9393 })
9494 return err
9595}
9696
9797// DropNamespace deletes the namespace with the given name.
9898func (d * Dgraph ) DropNamespace (ctx context.Context , name string ) error {
99- req := & apiv25 .DropNamespaceRequest {NsName : name }
100- _ , err := doWithRetryLogin (ctx , d , func (dc apiv25 .DgraphClient ) (* apiv25 .DropNamespaceResponse , error ) {
99+ req := & apiv2 .DropNamespaceRequest {NsName : name }
100+ _ , err := doWithRetryLogin (ctx , d , func (dc apiv2 .DgraphClient ) (* apiv2 .DropNamespaceResponse , error ) {
101101 return dc .DropNamespace (d .getContext (ctx ), req )
102102 })
103103 return err
104104}
105105
106106// RenameNamespace renames the namespace from the given name to the new name.
107107func (d * Dgraph ) RenameNamespace (ctx context.Context , from string , to string ) error {
108- req := & apiv25 .UpdateNamespaceRequest {NsName : from , RenameToNs : to }
109- _ , err := doWithRetryLogin (ctx , d , func (dc apiv25 .DgraphClient ) (* apiv25 .UpdateNamespaceResponse , error ) {
108+ req := & apiv2 .UpdateNamespaceRequest {NsName : from , RenameToNs : to }
109+ _ , err := doWithRetryLogin (ctx , d , func (dc apiv2 .DgraphClient ) (* apiv2 .UpdateNamespaceResponse , error ) {
110110 return dc .UpdateNamespace (d .getContext (ctx ), req )
111111 })
112112 return err
113113}
114114
115115// ListNamespaces returns a map of namespace names to their details.
116- func (d * Dgraph ) ListNamespaces (ctx context.Context ) (map [string ]* apiv25 .Namespace , error ) {
117- resp , err := doWithRetryLogin (ctx , d , func (dc apiv25 .DgraphClient ) (* apiv25 .ListNamespacesResponse , error ) {
118- return dc .ListNamespaces (d .getContext (ctx ), & apiv25 .ListNamespacesRequest {})
116+ func (d * Dgraph ) ListNamespaces (ctx context.Context ) (map [string ]* apiv2 .Namespace , error ) {
117+ resp , err := doWithRetryLogin (ctx , d , func (dc apiv2 .DgraphClient ) (* apiv2 .ListNamespacesResponse , error ) {
118+ return dc .ListNamespaces (d .getContext (ctx ), & apiv2 .ListNamespacesRequest {})
119119 })
120120 if err != nil {
121121 return nil , err
@@ -124,19 +124,19 @@ func (d *Dgraph) ListNamespaces(ctx context.Context) (map[string]*apiv25.Namespa
124124 return resp .NsList , nil
125125}
126126
127- func (d * Dgraph ) anyClientv25 () apiv25 .DgraphClient {
127+ func (d * Dgraph ) anyClientv2 () apiv2 .DgraphClient {
128128 //nolint:gosec
129- return d .dcv25 [rand .Intn (len (d .dcv25 ))]
129+ return d .dcv2 [rand .Intn (len (d .dcv2 ))]
130130}
131131
132132func doWithRetryLogin [T any ](ctx context.Context , d * Dgraph ,
133- f func (dc apiv25 .DgraphClient ) (* T , error )) (* T , error ) {
133+ f func (dc apiv2 .DgraphClient ) (* T , error )) (* T , error ) {
134134
135135 if d .useV1 {
136136 return nil , ErrUnsupportedAPI
137137 }
138138
139- dc := d .anyClientv25 ()
139+ dc := d .anyClientv2 ()
140140 resp , err := f (dc )
141141 if isJwtExpired (err ) {
142142 if err := d .retryLogin (ctx ); err != nil {
0 commit comments