From 7d23851445d806a355ba38bace530428e6a65454 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Thu, 20 May 2021 14:38:45 -0400 Subject: [PATCH 1/5] Add read only query support. --- client_test.go | 20 ++++++++++++++++++++ graph.go | 11 +++++++++++ 2 files changed, 31 insertions(+) diff --git a/client_test.go b/client_test.go index f0a484a..b4b7692 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 TestMatchQueryRO(t *testing.T) { + q := "MATCH (s)-[e]->(d) RETURN s,e,d" + res, err := graph.QueryRO(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 TestCreateQueryROFailure(t *testing.T) { + q := "CREATE (w:WorkPlace {name:'RedisLabs'})" + _, err := graph.QueryRO(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..a332c85 100644 --- a/graph.go +++ b/graph.go @@ -108,6 +108,17 @@ func (g *Graph) Query(q string) (*QueryResult, error) { return QueryResultNew(g, r) } +// QueryRO executes a read only query against the graph. +func (g *Graph) QueryRO(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 From 3618655fa34197bf9e091af6c4e6b2b36419529e Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Fri, 21 May 2021 11:35:42 -0400 Subject: [PATCH 2/5] Rename QueryRO to ROQuery. --- client_test.go | 8 ++++---- graph.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client_test.go b/client_test.go index b4b7692..b1869ba 100644 --- a/client_test.go +++ b/client_test.go @@ -68,9 +68,9 @@ func TestMatchQuery(t *testing.T) { checkQueryResults(t, res) } -func TestMatchQueryRO(t *testing.T) { +func TestMatchROQuery(t *testing.T) { q := "MATCH (s)-[e]->(d) RETURN s,e,d" - res, err := graph.QueryRO(q) + res, err := graph.ROQuery(q) if err != nil { t.Error(err) } @@ -134,9 +134,9 @@ func TestCreateQuery(t *testing.T) { assert.Equal(t, w.Label, "WorkPlace", "Unexpected node label.") } -func TestCreateQueryROFailure(t *testing.T) { +func TestCreateROQueryFailure(t *testing.T) { q := "CREATE (w:WorkPlace {name:'RedisLabs'})" - _, err := graph.QueryRO(q) + _, err := graph.ROQuery(q) assert.NotNil(t, err, "error should not be nil") } diff --git a/graph.go b/graph.go index a332c85..0b80183 100644 --- a/graph.go +++ b/graph.go @@ -108,8 +108,8 @@ func (g *Graph) Query(q string) (*QueryResult, error) { return QueryResultNew(g, r) } -// QueryRO executes a read only query against the graph. -func (g *Graph) QueryRO(q string) (*QueryResult, error) { +// 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 { From 683f759fe9b03128f8a6e58d51ec7fc03eeb7421 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Sun, 23 May 2021 20:20:46 -0400 Subject: [PATCH 3/5] Rename to RO_Query. --- client_test.go | 8 ++++---- graph.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client_test.go b/client_test.go index b1869ba..07e1eb1 100644 --- a/client_test.go +++ b/client_test.go @@ -68,9 +68,9 @@ func TestMatchQuery(t *testing.T) { checkQueryResults(t, res) } -func TestMatchROQuery(t *testing.T) { +func TestMatchRO_Query(t *testing.T) { q := "MATCH (s)-[e]->(d) RETURN s,e,d" - res, err := graph.ROQuery(q) + res, err := graph.RO_Query(q) if err != nil { t.Error(err) } @@ -134,9 +134,9 @@ func TestCreateQuery(t *testing.T) { assert.Equal(t, w.Label, "WorkPlace", "Unexpected node label.") } -func TestCreateROQueryFailure(t *testing.T) { +func TestCreateRO_QueryFailure(t *testing.T) { q := "CREATE (w:WorkPlace {name:'RedisLabs'})" - _, err := graph.ROQuery(q) + _, err := graph.RO_Query(q) assert.NotNil(t, err, "error should not be nil") } diff --git a/graph.go b/graph.go index 0b80183..cee3460 100644 --- a/graph.go +++ b/graph.go @@ -108,8 +108,8 @@ 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) { +// RO_Query executes a read only query against the graph. +func (g *Graph) RO_Query(q string) (*QueryResult, error) { r, err := g.Conn.Do("GRAPH.RO_QUERY", g.Id, q, "--compact") if err != nil { From 84473a43cd07007405402714ef1fa34a902f0936 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Mon, 24 May 2021 13:55:24 +0100 Subject: [PATCH 4/5] Reverted RO_Graph to Go naming convention --- client_test.go | 4 ++-- graph.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client_test.go b/client_test.go index 07e1eb1..84757f0 100644 --- a/client_test.go +++ b/client_test.go @@ -70,7 +70,7 @@ func TestMatchQuery(t *testing.T) { func TestMatchRO_Query(t *testing.T) { q := "MATCH (s)-[e]->(d) RETURN s,e,d" - res, err := graph.RO_Query(q) + res, err := graph.ROQuery(q) if err != nil { t.Error(err) } @@ -136,7 +136,7 @@ func TestCreateQuery(t *testing.T) { func TestCreateRO_QueryFailure(t *testing.T) { q := "CREATE (w:WorkPlace {name:'RedisLabs'})" - _, err := graph.RO_Query(q) + _, err := graph.ROQuery(q) assert.NotNil(t, err, "error should not be nil") } diff --git a/graph.go b/graph.go index cee3460..0b80183 100644 --- a/graph.go +++ b/graph.go @@ -108,8 +108,8 @@ func (g *Graph) Query(q string) (*QueryResult, error) { return QueryResultNew(g, r) } -// RO_Query executes a read only query against the graph. -func (g *Graph) RO_Query(q string) (*QueryResult, error) { +// 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 { From 205e74b1e0fbec0deee528a890072ed945c6efc4 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Mon, 24 May 2021 15:01:40 +0100 Subject: [PATCH 5/5] Renamed test due to Reverted RO_Graph to Go naming convention --- client_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client_test.go b/client_test.go index 84757f0..b1869ba 100644 --- a/client_test.go +++ b/client_test.go @@ -68,7 +68,7 @@ func TestMatchQuery(t *testing.T) { checkQueryResults(t, res) } -func TestMatchRO_Query(t *testing.T) { +func TestMatchROQuery(t *testing.T) { q := "MATCH (s)-[e]->(d) RETURN s,e,d" res, err := graph.ROQuery(q) if err != nil { @@ -134,7 +134,7 @@ func TestCreateQuery(t *testing.T) { assert.Equal(t, w.Label, "WorkPlace", "Unexpected node label.") } -func TestCreateRO_QueryFailure(t *testing.T) { +func TestCreateROQueryFailure(t *testing.T) { q := "CREATE (w:WorkPlace {name:'RedisLabs'})" _, err := graph.ROQuery(q) assert.NotNil(t, err, "error should not be nil")