@@ -8,9 +8,19 @@ import (
8
8
"github.com/gomodule/redigo/redis"
9
9
)
10
10
11
+ // QueryMode is the query mode
12
+ type QueryMode string
13
+
14
+ const (
15
+ // ReadQuery is a read query
16
+ ReadQuery QueryMode = "READ"
17
+ // WriteQuery is a write query
18
+ WriteQuery QueryMode = "WRITE"
19
+ )
20
+
11
21
// QueryOptions are a set of additional arguments to be emitted with a query.
12
22
type QueryOptions struct {
13
- timeout int
23
+ timeout int
14
24
}
15
25
16
26
// Graph represents a graph, which is a collection of nodes and edges.
@@ -110,7 +120,7 @@ func (g *Graph) Commit() (*QueryResult, error) {
110
120
// NewQueryOptions instantiates a new QueryOptions struct.
111
121
func NewQueryOptions () * QueryOptions {
112
122
return & QueryOptions {
113
- timeout : - 1 ,
123
+ timeout : - 1 ,
114
124
}
115
125
}
116
126
@@ -147,17 +157,17 @@ func (g *Graph) ROQuery(q string) (*QueryResult, error) {
147
157
}
148
158
149
159
func (g * Graph ) ParameterizedQuery (q string , params map [string ]interface {}) (* QueryResult , error ) {
150
- if ( params != nil ) {
160
+ if params != nil {
151
161
q = BuildParamsHeader (params ) + q
152
162
}
153
- return g .Query (q );
163
+ return g .Query (q )
154
164
}
155
165
156
166
// QueryWithOptions issues a query with the given timeout
157
167
func (g * Graph ) QueryWithOptions (q string , options * QueryOptions ) (* QueryResult , error ) {
158
168
var r interface {}
159
169
var err error
160
- if ( options .timeout >= 0 ) {
170
+ if options .timeout >= 0 {
161
171
r , err = g .Conn .Do ("GRAPH.QUERY" , g .Id , q , "--compact" , "timeout" , options .timeout )
162
172
} else {
163
173
r , err = g .Conn .Do ("GRAPH.QUERY" , g .Id , q , "--compact" )
@@ -171,17 +181,17 @@ func (g *Graph) QueryWithOptions(q string, options *QueryOptions) (*QueryResult,
171
181
172
182
// ParameterizedQueryWithOptions issues a parameterized query with the given timeout
173
183
func (g * Graph ) ParameterizedQueryWithOptions (q string , params map [string ]interface {}, options * QueryOptions ) (* QueryResult , error ) {
174
- if ( params != nil ) {
184
+ if params != nil {
175
185
q = BuildParamsHeader (params ) + q
176
186
}
177
- return g .QueryWithOptions (q , options );
187
+ return g .QueryWithOptions (q , options )
178
188
}
179
189
180
190
// ROQueryWithOptions issues a read-only query with the given timeout
181
191
func (g * Graph ) ROQueryWithOptions (q string , options * QueryOptions ) (* QueryResult , error ) {
182
192
var r interface {}
183
193
var err error
184
- if ( options .timeout >= 0 ) {
194
+ if options .timeout >= 0 {
185
195
r , err = g .Conn .Do ("GRAPH.RO_QUERY" , g .Id , q , "--compact" , "timeout" , options .timeout )
186
196
} else {
187
197
r , err = g .Conn .Do ("GRAPH.RO_QUERY" , g .Id , q , "--compact" )
@@ -263,7 +273,7 @@ func (g *Graph) getProperty(propIdx int) string {
263
273
// Procedures
264
274
265
275
// CallProcedure invokes procedure.
266
- func (g * Graph ) CallProcedure (procedure string , yield []string , args ... interface {}) (* QueryResult , error ) {
276
+ func (g * Graph ) CallProcedure (procedure string , yield []string , mode QueryMode , args ... interface {}) (* QueryResult , error ) {
267
277
q := fmt .Sprintf ("CALL %s(" , procedure )
268
278
269
279
tmp := make ([]string , 0 , len (args ))
@@ -276,12 +286,16 @@ func (g *Graph) CallProcedure(procedure string, yield []string, args ...interfac
276
286
q += fmt .Sprintf (" YIELD %s" , strings .Join (yield , "," ))
277
287
}
278
288
289
+ if mode == ReadQuery {
290
+ return g .ROQuery (q )
291
+ }
292
+
279
293
return g .Query (q )
280
294
}
281
295
282
296
// Labels, retrieves all node labels.
283
297
func (g * Graph ) Labels () []string {
284
- qr , _ := g .CallProcedure ("db.labels" , nil )
298
+ qr , _ := g .CallProcedure ("db.labels" , nil , ReadQuery )
285
299
286
300
l := make ([]string , len (qr .results ))
287
301
@@ -293,7 +307,7 @@ func (g *Graph) Labels() []string {
293
307
294
308
// RelationshipTypes, retrieves all edge relationship types.
295
309
func (g * Graph ) RelationshipTypes () []string {
296
- qr , _ := g .CallProcedure ("db.relationshipTypes" , nil )
310
+ qr , _ := g .CallProcedure ("db.relationshipTypes" , nil , ReadQuery )
297
311
298
312
rt := make ([]string , len (qr .results ))
299
313
@@ -305,7 +319,7 @@ func (g *Graph) RelationshipTypes() []string {
305
319
306
320
// PropertyKeys, retrieves all properties names.
307
321
func (g * Graph ) PropertyKeys () []string {
308
- qr , _ := g .CallProcedure ("db.propertyKeys" , nil )
322
+ qr , _ := g .CallProcedure ("db.propertyKeys" , nil , ReadQuery )
309
323
310
324
p := make ([]string , len (qr .results ))
311
325
0 commit comments