diff --git a/client_test.go b/client_test.go index f0a484a..b1869ba 100644 --- a/client_test.go +++ b/client_test.go @@ -65,6 +65,20 @@ func TestMatchQuery(t *testing.T) { t.Error(err) } + checkQueryResults(t, res) +} + +func TestMatchROQuery(t *testing.T) { + q := "MATCH (s)-[e]->(d) RETURN s,e,d" + res, err := graph.ROQuery(q) + if err != nil { + t.Error(err) + } + + checkQueryResults(t, res) +} + +func checkQueryResults(t *testing.T, res *QueryResult) { assert.Equal(t, len(res.results), 1, "expecting 1 result record") res.Next() @@ -120,6 +134,12 @@ func TestCreateQuery(t *testing.T) { assert.Equal(t, w.Label, "WorkPlace", "Unexpected node label.") } +func TestCreateROQueryFailure(t *testing.T) { + q := "CREATE (w:WorkPlace {name:'RedisLabs'})" + _, err := graph.ROQuery(q) + assert.NotNil(t, err, "error should not be nil") +} + func TestErrorReporting(t *testing.T) { q := "RETURN toupper(5)" res, err := graph.Query(q) diff --git a/graph.go b/graph.go index 444fc2d..0b80183 100644 --- a/graph.go +++ b/graph.go @@ -108,6 +108,17 @@ func (g *Graph) Query(q string) (*QueryResult, error) { return QueryResultNew(g, r) } +// ROQuery executes a read only query against the graph. +func (g *Graph) ROQuery(q string) (*QueryResult, error) { + + r, err := g.Conn.Do("GRAPH.RO_QUERY", g.Id, q, "--compact") + if err != nil { + return nil, err + } + + return QueryResultNew(g, r) +} + func (g *Graph) ParameterizedQuery(q string, params map[string]interface{}) (*QueryResult, error) { if(params != nil){ q = BuildParamsHeader(params) + q