Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.

Commit b783f50

Browse files
Add vars map to QueryRaw
1 parent b13e6be commit b783f50

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

client.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* SPDX-FileCopyrightText: © Hypermode Inc. <hello@hypermode.com>
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package modusgraph
27

38
import (
@@ -27,7 +32,7 @@ type Client interface {
2732
GetSchema(context.Context) (string, error)
2833
DropAll(context.Context) error
2934
DropData(context.Context) error
30-
QueryRaw(context.Context, string) ([]byte, error)
35+
QueryRaw(context.Context, string, map[string]string) ([]byte, error)
3136

3237
DgraphClient() (*dgo.Dgraph, func(), error)
3338
}
@@ -288,7 +293,7 @@ func (c client) Query(ctx context.Context, model any) *dg.Query {
288293
}
289294
defer c.pool.put(client)
290295

291-
txn := dg.NewTxn(client)
296+
txn := dg.NewReadOnlyTxnContext(ctx, client)
292297
return txn.Get(model)
293298
}
294299

@@ -342,11 +347,11 @@ func (c client) DropData(ctx context.Context) error {
342347
return client.Alter(ctx, &api.Operation{DropOp: api.Operation_DATA})
343348
}
344349

345-
// QueryRaw implements raw querying (DQL syntax).
346-
func (c client) QueryRaw(ctx context.Context, q string) ([]byte, error) {
350+
// QueryRaw implements raw querying (DQL syntax) and optional variables.
351+
func (c client) QueryRaw(ctx context.Context, q string, vars map[string]string) ([]byte, error) {
347352
if c.engine != nil {
348353
ns := c.engine.GetDefaultNamespace()
349-
resp, err := ns.Query(ctx, q)
354+
resp, err := ns.QueryWithVars(ctx, q, vars)
350355
if err != nil {
351356
return nil, err
352357
}
@@ -361,7 +366,7 @@ func (c client) QueryRaw(ctx context.Context, q string) ([]byte, error) {
361366
defer c.pool.put(client)
362367

363368
txn := dg.NewReadOnlyTxnContext(ctx, client)
364-
resp, err := txn.Txn().Query(ctx, q)
369+
resp, err := txn.Txn().QueryWithVars(ctx, q, vars)
365370
if err != nil {
366371
return nil, err
367372
}

cmd/query/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func main() {
9797
start := time.Now()
9898

9999
// Execute the query
100-
resp, err := client.QueryRaw(ctx, query)
100+
resp, err := client.QueryRaw(ctx, query, nil)
101101
if err != nil {
102102
logger.Error(err, "Query execution failed")
103103
os.Exit(1)

0 commit comments

Comments
 (0)