Skip to content

Commit 7d23851

Browse files
committedMay 20, 2021
Add read only query support.
1 parent 852ca0d commit 7d23851

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
 

‎client_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ func TestMatchQuery(t *testing.T) {
6565
t.Error(err)
6666
}
6767

68+
checkQueryResults(t, res)
69+
}
70+
71+
func TestMatchQueryRO(t *testing.T) {
72+
q := "MATCH (s)-[e]->(d) RETURN s,e,d"
73+
res, err := graph.QueryRO(q)
74+
if err != nil {
75+
t.Error(err)
76+
}
77+
78+
checkQueryResults(t, res)
79+
}
80+
81+
func checkQueryResults(t *testing.T, res *QueryResult) {
6882
assert.Equal(t, len(res.results), 1, "expecting 1 result record")
6983

7084
res.Next()
@@ -120,6 +134,12 @@ func TestCreateQuery(t *testing.T) {
120134
assert.Equal(t, w.Label, "WorkPlace", "Unexpected node label.")
121135
}
122136

137+
func TestCreateQueryROFailure(t *testing.T) {
138+
q := "CREATE (w:WorkPlace {name:'RedisLabs'})"
139+
_, err := graph.QueryRO(q)
140+
assert.NotNil(t, err, "error should not be nil")
141+
}
142+
123143
func TestErrorReporting(t *testing.T) {
124144
q := "RETURN toupper(5)"
125145
res, err := graph.Query(q)

‎graph.go

+11
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ func (g *Graph) Query(q string) (*QueryResult, error) {
108108
return QueryResultNew(g, r)
109109
}
110110

111+
// QueryRO executes a read only query against the graph.
112+
func (g *Graph) QueryRO(q string) (*QueryResult, error) {
113+
114+
r, err := g.Conn.Do("GRAPH.RO_QUERY", g.Id, q, "--compact")
115+
if err != nil {
116+
return nil, err
117+
}
118+
119+
return QueryResultNew(g, r)
120+
}
121+
111122
func (g *Graph) ParameterizedQuery(q string, params map[string]interface{}) (*QueryResult, error) {
112123
if(params != nil){
113124
q = BuildParamsHeader(params) + q

0 commit comments

Comments
 (0)
Failed to load comments.