@@ -8,6 +8,11 @@ import (
8
8
"github.com/gomodule/redigo/redis"
9
9
)
10
10
11
+ // QueryOptions are a set of additional arguments to be emitted with a query.
12
+ type QueryOptions struct {
13
+ timeout int
14
+ }
15
+
11
16
// Graph represents a graph, which is a collection of nodes and edges.
12
17
type Graph struct {
13
18
Id string
@@ -97,9 +102,16 @@ func (g *Graph) Commit() (*QueryResult, error) {
97
102
return g .Query (q )
98
103
}
99
104
105
+ // QueryOptionsNew instantiates a new QueryOptions struct.
106
+ func QueryOptionsNew (timeout int ) QueryOptions {
107
+ options := QueryOptions {
108
+ timeout : timeout ,
109
+ }
110
+ return options
111
+ }
112
+
100
113
// Query executes a query against the graph.
101
114
func (g * Graph ) Query (q string ) (* QueryResult , error ) {
102
-
103
115
r , err := g .Conn .Do ("GRAPH.QUERY" , g .Id , q , "--compact" )
104
116
if err != nil {
105
117
return nil , err
@@ -126,6 +138,46 @@ func (g *Graph) ParameterizedQuery(q string, params map[string]interface{}) (*Qu
126
138
return g .Query (q );
127
139
}
128
140
141
+ // QueryWithOptions issues a query with the given timeout
142
+ func (g * Graph ) QueryWithOptions (q string , options QueryOptions ) (* QueryResult , error ) {
143
+ var r interface {}
144
+ var err error
145
+ if (options .timeout >= 0 ) {
146
+ r , err = g .Conn .Do ("GRAPH.QUERY" , g .Id , q , "--compact" , "timeout" , options .timeout )
147
+ } else {
148
+ r , err = g .Conn .Do ("GRAPH.QUERY" , g .Id , q , "--compact" )
149
+ }
150
+ if err != nil {
151
+ return nil , err
152
+ }
153
+
154
+ return QueryResultNew (g , r )
155
+ }
156
+
157
+ // ParameterizedQueryWithOptions issues a parameterized query with the given timeout
158
+ func (g * Graph ) ParameterizedQueryWithOptions (q string , params map [string ]interface {}, options QueryOptions ) (* QueryResult , error ) {
159
+ if (params != nil ){
160
+ q = BuildParamsHeader (params ) + q
161
+ }
162
+ return g .QueryWithOptions (q , options );
163
+ }
164
+
165
+ // ROQueryWithOptions issues a read-only query with the given timeout
166
+ func (g * Graph ) ROQueryWithOptions (q string , options QueryOptions ) (* QueryResult , error ) {
167
+ var r interface {}
168
+ var err error
169
+ if (options .timeout >= 0 ) {
170
+ r , err = g .Conn .Do ("GRAPH.RO_QUERY" , g .Id , q , "--compact" , "timeout" , options .timeout )
171
+ } else {
172
+ r , err = g .Conn .Do ("GRAPH.RO_QUERY" , g .Id , q , "--compact" )
173
+ }
174
+ if err != nil {
175
+ return nil , err
176
+ }
177
+
178
+ return QueryResultNew (g , r )
179
+ }
180
+
129
181
// Merge pattern
130
182
func (g * Graph ) Merge (p string ) (* QueryResult , error ) {
131
183
q := fmt .Sprintf ("MERGE %s" , p )
0 commit comments