From 70ad09537af5c682a9eab11c96f8a8af42df3b99 Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Tue, 3 Jan 2023 21:31:09 +0500 Subject: [PATCH 01/16] adding custom changes to grammes fork --- manager/addvertex.go | 10 ++++++- model/vertex_query.go | 37 ++++++++++++++++++++++++ query/traversal/stringstep.go | 14 +++++++++ query/traversal/stringstep_test.go | 46 ++++++++++++++++++++++++++++++ query/traversal/util.go | 34 ++++++++++++++++++++++ 5 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 query/traversal/stringstep.go create mode 100644 query/traversal/stringstep_test.go diff --git a/manager/addvertex.go b/manager/addvertex.go index ce29600..d4930cd 100644 --- a/manager/addvertex.go +++ b/manager/addvertex.go @@ -102,7 +102,15 @@ func (v *addVertexQueryManager) AddVertex(label string, properties ...interface{ query := traversal.NewTraversal().AddV(label) for i := 0; i < len(properties); i += 2 { - query.AddStep("property", properties[i], properties[i+1]) + k := properties[i] + v := properties[i+1] + switch v.(type) { + case []interface{}: + vInterfaceArray := v.([]interface{}) + query.AddSetProperty(k.(string), vInterfaceArray) + default: + query.AddStep("property", k, v) + } } return v.AddVertexByString(query.String()) diff --git a/model/vertex_query.go b/model/vertex_query.go index 3efdf37..34da14e 100644 --- a/model/vertex_query.go +++ b/model/vertex_query.go @@ -212,3 +212,40 @@ func (v *Vertex) AddProperty(client queryClient, key string, value interface{}) return v.QueryRefresh(client) } + +type EdgeWithPropsAndLabel struct { + Label string + Id int64 + Properties []interface{} +} + +func (v *Vertex) AddEdges(client queryClient, edges []EdgeWithPropsAndLabel) error { + if client == nil { + return gremerror.NewGrammesError("AddEdges", gremerror.ErrNilClient) + } + + var query = newTrav().V().HasID(v.ID()) + + for i, edge := range edges { + if i != 0 { + query = query.OutV() + } + query = query.AddE(edge.Label).To(newTrav().V().HasID(edge.Id).Raw()) + + if len(edge.Properties)%2 != 0 { + return gremerror.NewGrammesError("AddEdges", gremerror.ErrOddNumberOfParameters) + } + + if len(edge.Properties) > 0 { + for i := 0; i < len(edge.Properties); i += 2 { + query.AddStep("property", edge.Properties[i], edge.Properties[i+1]) + } + } + } + + _, err := client.ExecuteQuery(query) + if err != nil { + return gremerror.NewQueryError("AddEdges", query.String(), err) + } + return nil +} diff --git a/query/traversal/stringstep.go b/query/traversal/stringstep.go new file mode 100644 index 0000000..406a33a --- /dev/null +++ b/query/traversal/stringstep.go @@ -0,0 +1,14 @@ +package traversal + +// StringStep adds a custom string to the traversal. This is not a gremlin step. +// Added for conveninece when the grammes library does not provide a step. +// Sample usage string_step("count()") +// User is responsible for the correctness of the string. +func (g String) StringStep(traversal string) String { + g.buffer.Reset() + + g.buffer.WriteString("." + traversal) + + g.string += g.buffer.String() + return g +} diff --git a/query/traversal/stringstep_test.go b/query/traversal/stringstep_test.go new file mode 100644 index 0000000..b09da1a --- /dev/null +++ b/query/traversal/stringstep_test.go @@ -0,0 +1,46 @@ +// Copyright (c) 2018 Northwestern Mutual. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package traversal + +import ( + "testing" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestStringStep(t *testing.T) { + Convey("Given a ) String { that represents the graph's traversal", t, func() { + g := NewTraversal() + Convey("When 'StringStep' is called with a string step count()", func() { + result := g.StringStep("count()") + Convey("Then result should equal 'g.count()'", func() { + So(result.String(), ShouldEqual, "g.count()") + }) + }) + + Convey("When 'StringStep' is called with a string step values()", func() { + result := g.Values() + Convey("Then result should equal 'g.values()'", func() { + So(result.String(), ShouldEqual, "g.values()") + }) + }) + }) +} diff --git a/query/traversal/util.go b/query/traversal/util.go index 32cd0ba..6ff2ab0 100644 --- a/query/traversal/util.go +++ b/query/traversal/util.go @@ -88,6 +88,10 @@ func (g *String) AddStep(step string, params ...interface{}) { g.buffer.Write(t) case string: g.buffer.WriteString("\"" + strings.ReplaceAll(t, "\"", "\\\"") + "\"") + case int64, uint64: + g.buffer.WriteString(fmt.Sprintf("%dL", p)) + case float32, float64: + g.buffer.WriteString(fmt.Sprintf("%fd", p)) default: g.buffer.WriteString(fmt.Sprintf("%v", t)) } @@ -118,3 +122,33 @@ func gatherInts(params ...int) string { return "" } } + +func (g *String) AddListProperty(k string, v []string) { + g.buffer.Reset() + + for _, vv := range v { + g.buffer.WriteString(fmt.Sprintf(".property(list, \"%s\", \"%s\")", k, vv)) + } + g.string += g.buffer.String() +} + +func (g *String) AddSetProperty(k string, v []interface{}) { + g.buffer.Reset() + + for _, vv := range v { + switch value := vv.(type) { + case float64, float32: + g.buffer.WriteString(fmt.Sprintf(`.property(set, "%s", %fd)`, k, value)) + case int64: + g.buffer.WriteString(fmt.Sprintf(`.property(set, "%s", %dL)`, k, value)) + case int, bool: + g.buffer.WriteString(fmt.Sprintf(".property(set, \"%s\", %v)", k, value)) + case string: + g.buffer.WriteString(fmt.Sprintf(".property(set, \"%s\", \"%s\")", k, value)) + default: + g.buffer.WriteString(fmt.Sprintf(".property(set, \"%s\", \"%s\")", k, value)) + } + } + + g.string += g.buffer.String() +} From d471d493be2c31cc57d0dea643bdee9e708c8d3e Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Tue, 3 Jan 2023 23:53:54 +0500 Subject: [PATCH 02/16] took a diff with grammes in gitlab and merged all changes --- examples/add-vertex-by-struct/main.go | 2 +- examples/all-vertices/main.go | 2 +- examples/id-by-label/main.go | 2 +- examples/id-by-property/main.go | 2 +- examples/id-by-query/main.go | 2 +- examples/id-by-string/main.go | 2 +- examples/vertex-by-id/main.go | 2 +- examples/vertex-edge-example/main.go | 14 ++++----- examples/vertices-by-label/main.go | 2 +- examples/vertices-by-property/main.go | 2 +- examples/vertices-by-query/main.go | 2 +- examples/vertices-by-string/main.go | 2 +- gremconnect/response.go | 25 +++++++-------- gremconnect/response_test.go | 19 ++++++----- gremconnect/websocket.go | 4 +-- gremerror/networkerror.go | 5 +-- manager/addvertex_test.go | 19 ++++++----- manager/dropvertex.go | 8 ++--- manager/getvertex.go | 5 ++- manager/misc.go | 40 ++++++++++-------------- manager/model.go | 24 +++++++------- manager/model_test.go | 4 +-- manager/schema.go | 8 ++--- manager/vertexid.go | 12 +++---- model.go | 11 +++++++ model/edge.go | 12 +++---- model/edge_test.go | 12 ++++--- model/edgeid.go | 35 +++++++++++++++++++++ model/edgevalue.go | 13 ++++++-- model/idlist.go | 2 +- model/unmarshal.go | 17 ++++++++++ model/vertex.go | 5 +-- model/vertex_query.go | 2 +- model/vertex_test.go | 16 +++++----- model/vertexid.go | 28 +++++++++++++++++ model/vertexproperty.go | 10 ++++-- query/cardinality/cardinality.go | 6 ++-- query/graph/makepropertykey_test.go | 10 +++--- query/traversal/addproperty.go | 45 ++++++++++++++++++++++++--- query/traversal/addproperty_test.go | 4 +-- query/traversal/graph.go | 12 +++++-- query/traversal/to.go | 2 +- query/traversal/util.go | 0 quick/dropvertex.go | 2 +- quick/getvertex.go | 2 +- quick/misc.go | 2 +- quick/schema.go | 6 ++-- quick/util.go | 8 ++--- quick/vertexid.go | 6 ++-- 49 files changed, 311 insertions(+), 166 deletions(-) mode change 100644 => 100755 examples/add-vertex-by-struct/main.go mode change 100644 => 100755 examples/all-vertices/main.go mode change 100644 => 100755 examples/id-by-label/main.go mode change 100644 => 100755 examples/id-by-property/main.go mode change 100644 => 100755 examples/id-by-query/main.go mode change 100644 => 100755 examples/id-by-string/main.go mode change 100644 => 100755 examples/vertex-by-id/main.go mode change 100644 => 100755 examples/vertex-edge-example/main.go mode change 100644 => 100755 examples/vertices-by-label/main.go mode change 100644 => 100755 examples/vertices-by-property/main.go mode change 100644 => 100755 examples/vertices-by-query/main.go mode change 100644 => 100755 examples/vertices-by-string/main.go mode change 100644 => 100755 gremconnect/response.go mode change 100644 => 100755 gremconnect/response_test.go mode change 100644 => 100755 gremconnect/websocket.go mode change 100644 => 100755 gremerror/networkerror.go mode change 100644 => 100755 manager/addvertex_test.go mode change 100644 => 100755 manager/dropvertex.go mode change 100644 => 100755 manager/getvertex.go mode change 100644 => 100755 manager/misc.go mode change 100644 => 100755 manager/model.go mode change 100644 => 100755 manager/model_test.go mode change 100644 => 100755 manager/schema.go mode change 100644 => 100755 manager/vertexid.go mode change 100644 => 100755 model.go mode change 100644 => 100755 model/edge.go mode change 100644 => 100755 model/edge_test.go create mode 100755 model/edgeid.go mode change 100644 => 100755 model/edgevalue.go mode change 100644 => 100755 model/idlist.go mode change 100644 => 100755 model/unmarshal.go mode change 100644 => 100755 model/vertex.go mode change 100644 => 100755 model/vertex_query.go mode change 100644 => 100755 model/vertex_test.go create mode 100755 model/vertexid.go mode change 100644 => 100755 model/vertexproperty.go mode change 100644 => 100755 query/cardinality/cardinality.go mode change 100644 => 100755 query/graph/makepropertykey_test.go mode change 100644 => 100755 query/traversal/addproperty.go mode change 100644 => 100755 query/traversal/addproperty_test.go mode change 100644 => 100755 query/traversal/graph.go mode change 100644 => 100755 query/traversal/to.go mode change 100644 => 100755 query/traversal/util.go mode change 100644 => 100755 quick/dropvertex.go mode change 100644 => 100755 quick/getvertex.go mode change 100644 => 100755 quick/misc.go mode change 100644 => 100755 quick/schema.go mode change 100644 => 100755 quick/util.go mode change 100644 => 100755 quick/vertexid.go diff --git a/examples/add-vertex-by-struct/main.go b/examples/add-vertex-by-struct/main.go old mode 100644 new mode 100755 index e6c83a8..ea6511d --- a/examples/add-vertex-by-struct/main.go +++ b/examples/add-vertex-by-struct/main.go @@ -70,7 +70,7 @@ func main() { // Print out the resulting vertex and its values. logger.Info("Vertex", zap.String("label", vertex.Label())) - logger.Info("Vertex", zap.Any("ID", vertex.ID())) + logger.Info("Vertex", zap.Int64("ID", vertex.ID())) for k, v := range vertex.PropertyMap() { logger.Info("Property", zap.Any(k, v[0].GetValue())) diff --git a/examples/all-vertices/main.go b/examples/all-vertices/main.go old mode 100644 new mode 100755 index d0277ee..46581d0 --- a/examples/all-vertices/main.go +++ b/examples/all-vertices/main.go @@ -73,7 +73,7 @@ func main() { for _, vertex := range vertices { logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Any("id", vertex.ID()), + zap.Int64("id", vertex.ID()), ) } } diff --git a/examples/id-by-label/main.go b/examples/id-by-label/main.go old mode 100644 new mode 100755 index 3cf8172..a266f6f --- a/examples/id-by-label/main.go +++ b/examples/id-by-label/main.go @@ -73,6 +73,6 @@ func main() { // Print out all the received vertex IDs. // This should only print out one ID. for _, id := range ids { - logger.Info("vertex id", zap.Any("value", id)) + logger.Info("vertex id", zap.Int64("value", id)) } } diff --git a/examples/id-by-property/main.go b/examples/id-by-property/main.go old mode 100644 new mode 100755 index 37e3dfa..9d10a81 --- a/examples/id-by-property/main.go +++ b/examples/id-by-property/main.go @@ -74,6 +74,6 @@ func main() { // Print out all the received vertex IDs. // This should only print out one ID. for _, id := range ids { - logger.Info("vertex id", zap.Any("value", id)) + logger.Info("vertex id", zap.Int64("value", id)) } } diff --git a/examples/id-by-query/main.go b/examples/id-by-query/main.go old mode 100644 new mode 100755 index 1fba6b1..7f77a2d --- a/examples/id-by-query/main.go +++ b/examples/id-by-query/main.go @@ -75,6 +75,6 @@ func main() { // Print out all the received vertex IDs. for _, id := range ids { - logger.Info("vertex id", zap.Any("value", id)) + logger.Info("vertex id", zap.Int64("value", id)) } } diff --git a/examples/id-by-string/main.go b/examples/id-by-string/main.go old mode 100644 new mode 100755 index 3849ffc..2f06aaa --- a/examples/id-by-string/main.go +++ b/examples/id-by-string/main.go @@ -72,6 +72,6 @@ func main() { // Print out all the received vertex IDs. for _, id := range ids { - logger.Info("vertex id", zap.Any("value", id)) + logger.Info("vertex id", zap.Int64("value", id)) } } diff --git a/examples/vertex-by-id/main.go b/examples/vertex-by-id/main.go old mode 100644 new mode 100755 index 9dda5bd..fad65f9 --- a/examples/vertex-by-id/main.go +++ b/examples/vertex-by-id/main.go @@ -78,6 +78,6 @@ func main() { // Print out the received vertex. logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Any("id", vertex.ID()), + zap.Int64("id", vertex.ID()), ) } diff --git a/examples/vertex-edge-example/main.go b/examples/vertex-edge-example/main.go old mode 100644 new mode 100755 index 88a267a..3c7a37a --- a/examples/vertex-edge-example/main.go +++ b/examples/vertex-edge-example/main.go @@ -114,24 +114,24 @@ func printEdges(client *grammes.Client, edges []grammes.Edge) { } // Print the information about the edge including // its ID, label, and its properties. - + logger.Info("Edge", - zap.Any("ID", edges[0].ID()), + zap.String("ID", edges[0].ID()), zap.String("Label", edges[0].Label()), zap.Any("ageDiff", edges[0].PropertyValue("ageDiff")), zap.Any("driveDist", edges[0].PropertyValue("driveDist")), ) - + logger.Info("OutVertex", - zap.Any("ID", edges[0].OutVertexID()), + zap.Int64("ID", edges[0].OutVertexID()), zap.String("Label", edges[0].OutVertexLabel()), zap.Any("Name", v1.PropertyValue("name", 0)), ) - + logger.Info("InVertex", - zap.Any("ID", edges[0].InVertexID()), + zap.Int64("ID", edges[0].InVertexID()), zap.String("Label", edges[0].InVertexLabel()), zap.Any("Name", v2.PropertyValue("name", 0)), ) } -} \ No newline at end of file +} diff --git a/examples/vertices-by-label/main.go b/examples/vertices-by-label/main.go old mode 100644 new mode 100755 index 7d54c29..a29354e --- a/examples/vertices-by-label/main.go +++ b/examples/vertices-by-label/main.go @@ -74,7 +74,7 @@ func main() { for _, vertex := range vertices { logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Any("id", vertex.ID()), + zap.Int64("id", vertex.ID()), ) } } diff --git a/examples/vertices-by-property/main.go b/examples/vertices-by-property/main.go old mode 100644 new mode 100755 index 4a6bd5e..e7e4fb5 --- a/examples/vertices-by-property/main.go +++ b/examples/vertices-by-property/main.go @@ -74,7 +74,7 @@ func main() { for _, vertex := range vertices { logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Any("id", vertex.ID()), + zap.Int64("id", vertex.ID()), zap.Any("name", vertex.PropertyValue("name", 0)), ) } diff --git a/examples/vertices-by-query/main.go b/examples/vertices-by-query/main.go old mode 100644 new mode 100755 index 8d339c1..91c4b2b --- a/examples/vertices-by-query/main.go +++ b/examples/vertices-by-query/main.go @@ -76,7 +76,7 @@ func main() { for _, vertex := range vertices { logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Any("id", vertex.ID()), + zap.Int64("id", vertex.ID()), ) } } diff --git a/examples/vertices-by-string/main.go b/examples/vertices-by-string/main.go old mode 100644 new mode 100755 index 2758a2c..fc72658 --- a/examples/vertices-by-string/main.go +++ b/examples/vertices-by-string/main.go @@ -73,7 +73,7 @@ func main() { for _, vertex := range vertices { logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Any("id", vertex.ID()), + zap.Int64("id", vertex.ID()), ) } } diff --git a/gremconnect/response.go b/gremconnect/response.go old mode 100644 new mode 100755 index 6122694..47e4878 --- a/gremconnect/response.go +++ b/gremconnect/response.go @@ -53,9 +53,8 @@ func MarshalResponse(msg []byte) (Response, error) { code = status["code"].(float64) resp = Response{Code: int(code)} ) - message, _ := status["message"].(string) - err = responseDetectError(resp.Code, message) + err = responseDetectError(resp.Code) if err != nil { resp.Data = err // Use the Data field as a vehicle for the error. } else { @@ -68,7 +67,7 @@ func MarshalResponse(msg []byte) (Response, error) { // responseDetectError detects any possible errors in responses // from Gremlin Server and generates an error for each code -func responseDetectError(code int, message string) error { +func responseDetectError(code int) error { switch code { case 200: break @@ -77,25 +76,25 @@ func responseDetectError(code int, message string) error { case 206: break case 401: - return gremerror.NewNetworkError(401, "UNAUTHORIZED", message) + return gremerror.NewNetworkError(401, "UNAUTHORIZED") case 407: - return gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED", message) + return gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED") case 498: - return gremerror.NewNetworkError(498, "MALFORMED REQUEST", message) + return gremerror.NewNetworkError(498, "MALFORMED REQUEST") case 499: - return gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS", message) + return gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS") case 500: - return gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR", message) + return gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR") case 503: - return gremerror.NewNetworkError(503, "SERVER UNAVAILABLE", message) + return gremerror.NewNetworkError(503, "SERVER UNAVAILABLE") case 597: - return gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR", message) + return gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR") case 598: - return gremerror.NewNetworkError(598, "SERVER TIMEOUT", message) + return gremerror.NewNetworkError(598, "SERVER TIMEOUT") case 599: - return gremerror.NewNetworkError(599, "SERIALIZATION ERROR", message) + return gremerror.NewNetworkError(599, "SERIALIZATION ERROR") default: - return gremerror.NewNetworkError(code, "UNKNOWN ERROR", message) + return gremerror.NewNetworkError(code, "UNKNOWN ERROR") } return nil } diff --git a/gremconnect/response_test.go b/gremconnect/response_test.go old mode 100644 new mode 100755 index 8ee1d45..7238d08 --- a/gremconnect/response_test.go +++ b/gremconnect/response_test.go @@ -77,7 +77,6 @@ var ( { "requestId": "d2476e5b-b2bc-6a70-2647-3991f68ab415", "status": { - "message": "Some error", "code": 401, "attributes": {} }, @@ -234,7 +233,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp401.Data should be 'UNAUTHORIZED'", func() { - So(resp401.Data, ShouldResemble, gremerror.NewNetworkError(401, "UNAUTHORIZED", "Some error")) + So(resp401.Data, ShouldResemble, gremerror.NewNetworkError(401, "UNAUTHORIZED")) }) Convey("Then the status code should be 407", func() { @@ -242,7 +241,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp407.Data should be 'AUTHENTICATE'", func() { - So(resp407.Data, ShouldResemble, gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED", "")) + So(resp407.Data, ShouldResemble, gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED")) }) Convey("Then the status code should be 498", func() { @@ -250,7 +249,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp498.Data should be 'MALFORMED REQUEST", func() { - So(resp498.Data, ShouldResemble, gremerror.NewNetworkError(498, "MALFORMED REQUEST", "")) + So(resp498.Data, ShouldResemble, gremerror.NewNetworkError(498, "MALFORMED REQUEST")) }) Convey("Then the status code should be 499", func() { @@ -258,7 +257,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp499.Data should be 'INVALID REQUEST ARGUMENTS'", func() { - So(resp499.Data, ShouldResemble, gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS", "")) + So(resp499.Data, ShouldResemble, gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS")) }) Convey("Then the status code should be 500", func() { @@ -266,7 +265,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp500.Data should be 'SERVER ERROR'", func() { - So(resp500.Data, ShouldResemble, gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR", "")) + So(resp500.Data, ShouldResemble, gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR")) }) Convey("Then the status code should be 597", func() { @@ -274,7 +273,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp597.Data should be 'SCRIPT EVALUATION ERROR'", func() { - So(resp597.Data, ShouldResemble, gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR", "")) + So(resp597.Data, ShouldResemble, gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR")) }) Convey("Then the status code should be 598", func() { @@ -282,7 +281,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp598.Data should be 'SERVER TIMEOUT'", func() { - So(resp598.Data, ShouldResemble, gremerror.NewNetworkError(598, "SERVER TIMEOUT", "")) + So(resp598.Data, ShouldResemble, gremerror.NewNetworkError(598, "SERVER TIMEOUT")) }) Convey("Then the status code should be 599", func() { @@ -290,11 +289,11 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp599.Data should be 'SERVER SERIALIZATION ERROR'", func() { - So(resp599.Data, ShouldResemble, gremerror.NewNetworkError(599, "SERIALIZATION ERROR", "")) + So(resp599.Data, ShouldResemble, gremerror.NewNetworkError(599, "SERIALIZATION ERROR")) }) Convey("Then respDefault.Data should be 'UNKNOWN ERROR'", func() { - So(respDefault.Data, ShouldResemble, gremerror.NewNetworkError(403, "UNKNOWN ERROR", "")) + So(respDefault.Data, ShouldResemble, gremerror.NewNetworkError(403, "UNKNOWN ERROR")) }) }) }) diff --git a/gremconnect/websocket.go b/gremconnect/websocket.go old mode 100644 new mode 100755 index 6a6bb40..a2b5c25 --- a/gremconnect/websocket.go +++ b/gremconnect/websocket.go @@ -54,8 +54,8 @@ type WebSocket struct { func (ws *WebSocket) Connect() error { var err error dialer := websocket.Dialer{ - WriteBufferSize: 1024 * 8, // Set up for large messages. - ReadBufferSize: 1024 * 8, // Set up for large messages. + WriteBufferSize: 1024 * 256, // Set up for large messages. + ReadBufferSize: 1024 * 256, // Set up for large messages. HandshakeTimeout: 5 * time.Second, } diff --git a/gremerror/networkerror.go b/gremerror/networkerror.go old mode 100644 new mode 100755 index 070dab5..8fc9d03 --- a/gremerror/networkerror.go +++ b/gremerror/networkerror.go @@ -26,15 +26,13 @@ import "strconv" type NetworkError struct { statusCode int msg string - origMsg string } // NewNetworkError returns a status code related error. -func NewNetworkError(statusCode int, msg string, origMsg string) error { +func NewNetworkError(statusCode int, msg string) error { return &NetworkError{ statusCode: statusCode, msg: msg, - origMsg: origMsg, } } @@ -43,6 +41,5 @@ func (g *NetworkError) Error() string { fmtError("type", "NETWORK_ERROR"), fmtError("status code", strconv.Itoa(g.statusCode)), fmtError("error", g.msg), - fmtError("original error", g.origMsg), ) } diff --git a/manager/addvertex_test.go b/manager/addvertex_test.go old mode 100644 new mode 100755 index 4f84510..7f81639 --- a/manager/addvertex_test.go +++ b/manager/addvertex_test.go @@ -34,15 +34,20 @@ import ( var testVertex = model.Vertex{ Type: "testType", Value: model.VertexValue{ - ID: 1234, + ID: model.ID{ + Type: "testID", + Value: 1234, + }, Label: "testLabel", Properties: model.PropertyMap{"testDetail": []model.Property{ - { + model.Property{ Type: "testType", Value: model.PropertyValue{ ID: model.PropertyID{ - Type: "testIDType", - Value: "testRelID", + Type: "testIDType", + Value: model.PropertyIDValue{ + RelationID: "testRelID", + }, }, Value: model.ValueWrapper{ PropertyDetailedValue: model.PropertyDetailedValue{ @@ -71,7 +76,7 @@ func TestAddAPIVertex(t *testing.T) { data.Properties = map[string]string{"testkey": "testval"} v, _ := qm.AddAPIVertex(data) Convey("Then the return vertex ID value should be 28720", func() { - So(v.Value.ID, ShouldEqual, 28720) + So(v.Value.ID.Value, ShouldEqual, 28720) }) }) }) @@ -98,7 +103,7 @@ func TestAddVertexByStruct(t *testing.T) { Convey("When AddVertexByStruct is called", func() { res, _ := qm.AddVertexByStruct(testVertex) Convey("Then the return vertex ID value should be 28720", func() { - So(res.Value.ID, ShouldEqual, 28720) + So(res.Value.ID.Value, ShouldEqual, 28720) }) }) }) @@ -164,7 +169,7 @@ func TestAddVertexByQuery(t *testing.T) { var q mockQuery res, _ := qm.AddVertexByQuery(q) Convey("Then the return vertex ID value should be 28720", func() { - So(res.Value.ID, ShouldEqual, 28720) + So(res.Value.ID.Value, ShouldEqual, 28720) }) }) }) diff --git a/manager/dropvertex.go b/manager/dropvertex.go old mode 100644 new mode 100755 index b40dddc..379e4b3 --- a/manager/dropvertex.go +++ b/manager/dropvertex.go @@ -23,10 +23,10 @@ package manager import ( "strings" - "github.com/northwesternmutual/grammes/query/traversal" "github.com/northwesternmutual/grammes/gremerror" "github.com/northwesternmutual/grammes/logging" "github.com/northwesternmutual/grammes/query" + "github.com/northwesternmutual/grammes/query/traversal" ) type dropQueryManager struct { @@ -53,7 +53,7 @@ func (v *dropQueryManager) DropVertexLabel(label string) error { return nil } -func (v *dropQueryManager) DropVertexByID(ids ...interface{}) error { +func (v *dropQueryManager) DropVertexByID(ids ...int64) error { var err error for _, id := range ids { query := traversal.NewTraversal().V().HasID(id).Drop() @@ -72,7 +72,7 @@ func (v *dropQueryManager) DropVerticesByString(q string) error { if !strings.HasSuffix(q, "drop()") { q += ".drop()" } - + _, err := v.executeStringQuery(q) if err != nil { v.logger.Error("invalid query", @@ -90,4 +90,4 @@ func (v *dropQueryManager) DropVerticesByQuery(q query.Query) error { ) } return err -} \ No newline at end of file +} diff --git a/manager/getvertex.go b/manager/getvertex.go old mode 100644 new mode 100755 index bf5cafd..c4efedf --- a/manager/getvertex.go +++ b/manager/getvertex.go @@ -21,7 +21,6 @@ package manager import ( - "fmt" "strconv" "github.com/northwesternmutual/grammes/gremerror" @@ -105,9 +104,9 @@ func (c *getVertexQueryManager) AllVertices() ([]model.Vertex, error) { // ID assigned to it. This ID is unique to every // vertex on the graph. This is the best way of finding // vertices without any conflicting labels or properties. -func (c *getVertexQueryManager) VertexByID(id interface{}) (model.Vertex, error) { +func (c *getVertexQueryManager) VertexByID(id int64) (model.Vertex, error) { // Query the graph for a vertex with this ID. - vertices, err := c.VerticesByString("g.V().hasId(" + fmt.Sprint(id) + ")") + vertices, err := c.VerticesByString("g.V().hasId(" + strconv.Itoa(int(id)) + ")") if err != nil { c.logger.Error("error gathering vertices", gremerror.NewGrammesError("VerticesByID", err), diff --git a/manager/misc.go b/manager/misc.go old mode 100644 new mode 100755 index 5f6eea6..c51c988 --- a/manager/misc.go +++ b/manager/misc.go @@ -21,8 +21,6 @@ package manager import ( - "errors" - "fmt" "strconv" "github.com/northwesternmutual/grammes/gremerror" @@ -48,7 +46,7 @@ func (m *miscQueryManager) DropAll() error { return err } -func (m *miscQueryManager) SetVertexProperty(id interface{}, keyAndVals ...interface{}) error { +func (m *miscQueryManager) SetVertexProperty(id int64, keyAndVals ...interface{}) error { if len(keyAndVals)%2 != 0 { m.logger.Error("number of parameters ["+strconv.Itoa(len(keyAndVals))+"]", gremerror.NewGrammesError("SetVertexProperty", gremerror.ErrOddNumberOfParameters), @@ -85,31 +83,25 @@ func (m *miscQueryManager) VertexCount() (int64, error) { return 0, err } - if len(responses) == 0 { - return 0, gremerror.ErrEmptyResponse - } + var resultingIDs model.IDList - var rawResp model.IDList + for _, res := range responses { + var rawIDs model.IDList - err = jsonUnmarshal(responses[0], &rawResp) - if err != nil { - m.logger.Error("unmarshal", - gremerror.NewUnmarshalError("VertexCount", responses[0], err), - ) - return 0, err - } + err = jsonUnmarshal(res, &rawIDs) + if err != nil { + m.logger.Error("id unmarshal", + gremerror.NewUnmarshalError("VertexCount", res, err), + ) + return 0, err + } - if len(rawResp.IDs) == 0 { - return 0, errors.New(fmt.Sprintf("invalid response %s", string(responses[0]))) - } - v, ok := rawResp.IDs[0].(map[string]interface{}) - if !ok { - return 0, errors.New(fmt.Sprintf("invalid response %s", string(responses[0]))) + resultingIDs.IDs = append(resultingIDs.IDs, rawIDs.IDs...) } - count, ok := v["@value"].(float64) - if !ok { - return 0, errors.New(fmt.Sprintf("invalid response %s", string(responses[0]))) + + if len(resultingIDs.IDs) == 0 { + return 0, gremerror.ErrEmptyResponse } - return int64(count), nil + return resultingIDs.IDs[0].Value, nil } diff --git a/manager/model.go b/manager/model.go old mode 100644 new mode 100755 index 1a5846e..658495d --- a/manager/model.go +++ b/manager/model.go @@ -42,15 +42,15 @@ var ( // unmarshalID will simply take a raw response and // unmarshal it into an ID. -func unmarshalID(data [][]byte) (id interface{}, err error) { +func unmarshalID(data [][]byte) (id int64, err error) { var resp model.VertexList for _, res := range data { var resPart model.VertexList err = jsonUnmarshal(res, &resPart) if err == nil { - if len(resPart.Vertices) > 0 { - id = resPart.Vertices[0].ID() + if len(resp.Vertices) > 0 { + id = resp.Vertices[0].ID() } } @@ -73,17 +73,17 @@ type MiscQuerier interface { // VertexCount will return the number of vertices on the graph. VertexCount() (count int64, err error) // SetVertexProperty will either add or set the property of a vertex. - SetVertexProperty(id interface{}, keyAndVals ...interface{}) error + SetVertexProperty(id int64, keyAndVals ...interface{}) error } // SchemaQuerier handles all schema related queries to the graph. type SchemaQuerier interface { // AddEdgeLabel adds a new edge label to the schema. - AddEdgeLabel(multi multiplicity.Multiplicity, label string) (id interface{}, err error) + AddEdgeLabel(multi multiplicity.Multiplicity, label string) (id int64, err error) // AddEdgeLabels adds new edge labels to the schema. - AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids []interface{}, err error) + AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids []int64, err error) // AddPropertyKey adds a new property key to the schema. - AddPropertyKey(label string, dt datatype.DataType, card cardinality.Cardinality) (id interface{}, err error) + AddPropertyKey(label string, dt datatype.DataType, card cardinality.Cardinality) (id int64, err error) // CommitSchema will finalize your changes and apply them to the schema. CommitSchema() (res [][]byte, err error) } @@ -93,7 +93,7 @@ type GetVertexQuerier interface { // AllVertices will return a slice of all vertices on the graph. AllVertices() (vertices []model.Vertex, err error) // VertexByID will return a single vertex based on the ID provided. - VertexByID(id interface{}) (vertex model.Vertex, err error) + VertexByID(id int64) (vertex model.Vertex, err error) // VerticesByString will return already unmarshalled vertex structs from a string query. VerticesByString(stringQuery string) (vertices []model.Vertex, err error) // VerticesByQuery will return already unmarshalled vertex structs from a query object. @@ -105,11 +105,11 @@ type GetVertexQuerier interface { // GetVertexIDQuerier holds functions to gather IDs from the graph. type GetVertexIDQuerier interface { // VertexIDsByString returns a slice of IDs from a string query. - VertexIDsByString(stringQuery string) (ids []interface{}, err error) + VertexIDsByString(stringQuery string) (ids []int64, err error) // VertexIDsByQuery returns a slice of IDs from a query object. - VertexIDsByQuery(queryObj query.Query) (ids []interface{}, err error) + VertexIDsByQuery(queryObj query.Query) (ids []int64, err error) // VertexIDs returns a slice of IDs based on the label and properties. - VertexIDs(label string, properties ...interface{}) (ids []interface{}, err error) + VertexIDs(label string, properties ...interface{}) (ids []int64, err error) } // AddVertexQuerier are queries specific to adding vertices. @@ -133,7 +133,7 @@ type DropQuerier interface { // DropVertexLabel drops all vertices with given label. DropVertexLabel(label string) error // DropVertexByID drops vertices based on their IDs. - DropVertexByID(ids ...interface{}) error + DropVertexByID(ids ...int64) error // DropVerticesByString drops vertices using a string query. DropVerticesByString(stringQuery string) error // DropVerticesByQuery drops vertices using a query object. diff --git a/manager/model_test.go b/manager/model_test.go old mode 100644 new mode 100755 index 528f82d..648a676 --- a/manager/model_test.go +++ b/manager/model_test.go @@ -32,8 +32,8 @@ func TestUnmarshalID(t *testing.T) { Convey("Given a byte ID response", t, func() { Convey("When unmarshalID is called", func() { id, _ := unmarshalID([][]byte{[]byte(vertexResponse)}) - Convey("Then the return ID should be 28720", func() { - So(id, ShouldEqual, 28720) + Convey("Then the return ID should be 0", func() { + So(id, ShouldEqual, 0) }) }) }) diff --git a/manager/schema.go b/manager/schema.go old mode 100644 new mode 100755 index 2877369..f5ca821 --- a/manager/schema.go +++ b/manager/schema.go @@ -46,7 +46,7 @@ func newSchemaManager(logger logging.Logger, executor stringExecutor) *schemaMan // AddEdgeLabel adds the edge label to the // graph directly. This method returns the schema id // of the edge label added. -func (s *schemaManager) AddEdgeLabel(multi multiplicity.Multiplicity, label string) (id interface{}, err error) { +func (s *schemaManager) AddEdgeLabel(multi multiplicity.Multiplicity, label string) (id int64, err error) { var ( data [][]byte query = graph.NewGraph().OpenManagement().MakeEdgeLabel(label).Multiplicity(multi).Make() @@ -78,7 +78,7 @@ func (s *schemaManager) AddEdgeLabel(multi multiplicity.Multiplicity, label stri // but with the ability to do multiple labels at a // time. This function is called similarly to your // favorite logger. -func (s *schemaManager) AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids []interface{}, err error) { +func (s *schemaManager) AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids []int64, err error) { if len(multiplicityAndLabels)%2 != 0 { s.logger.Error(fmt.Sprintf("number of parameters [%d]", len(multiplicityAndLabels)), gremerror.NewGrammesError("AddEdgeLabels", gremerror.ErrOddNumberOfParameters), @@ -89,7 +89,7 @@ func (s *schemaManager) AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids var ( multi multiplicity.Multiplicity label string - id interface{} + id int64 ok bool ) @@ -112,7 +112,7 @@ func (s *schemaManager) AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids // AddPropertyKey adds the edge label to the // graph directly. This method returns the schema id // of the edge label added. -func (s *schemaManager) AddPropertyKey(propertyName string, datatype datatype.DataType, cardinality cardinality.Cardinality) (id interface{}, err error) { +func (s *schemaManager) AddPropertyKey(propertyName string, datatype datatype.DataType, cardinality cardinality.Cardinality) (id int64, err error) { var ( data [][]byte query = graph.NewGraph().OpenManagement().MakePropertyKey(propertyName, datatype, cardinality).Make() diff --git a/manager/vertexid.go b/manager/vertexid.go old mode 100644 new mode 100755 index 09e77c0..07baea9 --- a/manager/vertexid.go +++ b/manager/vertexid.go @@ -46,7 +46,7 @@ func newVertexIDQueryManager(logger logging.Logger, executor stringExecutor) *ve // VertexIDsByString executes a string query and unmarshals the // IDs for the user. -func (v *vertexIDQueryManager) VertexIDsByString(q string) ([]interface{}, error) { +func (v *vertexIDQueryManager) VertexIDsByString(q string) ([]int64, error) { if !strings.HasSuffix(q, ".id()") { q += ".id()" } @@ -75,10 +75,10 @@ func (v *vertexIDQueryManager) VertexIDsByString(q string) ([]interface{}, error rawIDs.IDs = append(rawIDs.IDs, idPart.IDs...) } - var ids []interface{} + var ids []int64 for _, id := range rawIDs.IDs { - ids = append(ids, id) + ids = append(ids, id.Value) } return ids, nil @@ -86,8 +86,8 @@ func (v *vertexIDQueryManager) VertexIDsByString(q string) ([]interface{}, error // VertexIDsByQuery will take a query and execute it. Then it will // run through and extract all the vertex IDs matching the -// traversal and return them in an array. -func (v *vertexIDQueryManager) VertexIDsByQuery(query query.Query) ([]interface{}, error) { +// traversal and return them in an array of int64. +func (v *vertexIDQueryManager) VertexIDsByQuery(query query.Query) ([]int64, error) { ids, err := v.VertexIDsByString(query.String()) if err != nil { v.logger.Error("error gathering IDs", @@ -100,7 +100,7 @@ func (v *vertexIDQueryManager) VertexIDsByQuery(query query.Query) ([]interface{ // VertexIDs takes the label and optional properties to retrieve // the IDs desired from the graph. -func (v *vertexIDQueryManager) VertexIDs(label string, properties ...interface{}) ([]interface{}, error) { +func (v *vertexIDQueryManager) VertexIDs(label string, properties ...interface{}) ([]int64, error) { if len(properties)%2 != 0 { v.logger.Error("number of parameters ["+strconv.Itoa(len(properties))+"]", gremerror.NewGrammesError("VertexIDs", gremerror.ErrOddNumberOfParameters), diff --git a/model.go b/model.go old mode 100644 new mode 100755 index a7d6d6d..c9889b2 --- a/model.go +++ b/model.go @@ -38,6 +38,9 @@ var ( // UnmarshalEdgeList is a utility to unmarshal a list // or array of edges properly. UnmarshalEdgeList = model.UnmarshalEdgeList + // UnmarshalIDList is a utility to unmarshal a list + // or array of IDs properly. + UnmarshalIDList = model.UnmarshalIDList // UnmarshalVertexList is a utility to unmarshal a list // or array of vertices properly. UnmarshalVertexList = model.UnmarshalVertexList @@ -111,6 +114,14 @@ type PropertyMap = model.PropertyMap // value, and label of this property's value. type PropertyValue = model.PropertyValue +// ID is used to get quick access +// to the model.ID without having to +// import it everywhere in the grammes package. +// +// ID contains the data stores in the +// 'ID' data including the type and Value +type ID = model.ID + // APIData is used to get quick access // to the model.APIData without having to // import it everywhere in the grammes package. diff --git a/model/edge.go b/model/edge.go old mode 100644 new mode 100755 index b223e2d..60a964b --- a/model/edge.go +++ b/model/edge.go @@ -43,8 +43,8 @@ func (e *Edge) PropertyValue(key string) interface{} { } // ID will retrieve the Edge ID for you. -func (e *Edge) ID() interface{} { - return e.Value.ID +func (e *Edge) ID() string { + return e.Value.ID.Value.RelationID } // Label will retrieve the Edge Label for you. @@ -54,14 +54,14 @@ func (e *Edge) Label() string { // OutVertexID will retrieve the id for the // vertex that the edge goes out of. -func (e *Edge) OutVertexID() interface{} { - return e.Value.OutV +func (e *Edge) OutVertexID() (id int64) { + return e.Value.OutV.Value } // InVertexID will retrieve the id for the // vertex that the edge goes into. -func (e *Edge) InVertexID() interface{} { - return e.Value.InV +func (e *Edge) InVertexID() (id int64) { + return e.Value.InV.Value } // OutVertexLabel will retrieve the label diff --git a/model/edge_test.go b/model/edge_test.go old mode 100644 new mode 100755 index 5e1e328..d1f7b94 --- a/model/edge_test.go +++ b/model/edge_test.go @@ -41,7 +41,9 @@ func TestPropertyValue(t *testing.T) { func TestID(t *testing.T) { Convey("Given a variable that represents the Edge struct", t, func() { - e := Edge{Type: "tesType", Value: EdgeValue{ID: "testRelID"}} + // erid := EdgeRelationID{RelationID: "testRelID"} + // ev := EdgeValue{ID: EdgeID{Value: erid}} + e := Edge{Type: "tesType", Value: EdgeValue{ID: EdgeID{Value: EdgeRelationID{RelationID: "testRelID"}}}} Convey("When 'ID' is called", func() { result := e.ID() @@ -70,7 +72,7 @@ func TestOutVertexID(t *testing.T) { Convey("Given a variable that represents the Edge struct", t, func() { // erid := EdgeRelationID{RelationID: "testRelID"} // ev := EdgeValue{ID: EdgeID{Value: erid}} - e := Edge{Type: "tesType", Value: EdgeValue{OutV: 12345}} + e := Edge{Type: "tesType", Value: EdgeValue{OutV: EdgeVertex{Value: 12345}}} Convey("When 'OutVertexID' is called", func() { result := e.OutVertexID() @@ -83,7 +85,7 @@ func TestOutVertexID(t *testing.T) { func TestInVertexID(t *testing.T) { Convey("Given a variable that represents the Edge struct", t, func() { - e := Edge{Type: "tesType", Value: EdgeValue{InV: 54321}} + e := Edge{Type: "tesType", Value: EdgeValue{InV: EdgeVertex{Value: 54321}}} Convey("When 'InVertexID' is called", func() { result := e.InVertexID() @@ -124,7 +126,7 @@ func TestInVertexLabel(t *testing.T) { func TestQueryOutVertex(t *testing.T) { Convey("Given a variable that represents the Edge struct", t, func() { - e := Edge{Type: "tesType", Value: EdgeValue{OutV: 12345}} + e := Edge{Type: "tesType", Value: EdgeValue{OutV: EdgeVertex{Value: 12345}}} Convey("When 'QueryOutVertex' is called with a string", func() { var client queryClient @@ -139,7 +141,7 @@ func TestQueryOutVertex(t *testing.T) { func TestQueryInVertex(t *testing.T) { Convey("Given a variable that represents the Edge struct", t, func() { - e := Edge{Type: "tesType", Value: EdgeValue{OutV: 12345}} + e := Edge{Type: "tesType", Value: EdgeValue{OutV: EdgeVertex{Value: 12345}}} Convey("When 'QueryInVertex' is called with a string", func() { var client queryClient diff --git a/model/edgeid.go b/model/edgeid.go new file mode 100755 index 0000000..230f9a4 --- /dev/null +++ b/model/edgeid.go @@ -0,0 +1,35 @@ +// Copyright (c) 2018 Northwestern Mutual. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package model + +// EdgeID is the main wrapper struct +// that holds the type and ID itself. +type EdgeID struct { + Type string `json:"@type"` + Value EdgeRelationID `json:"@value"` +} + +// EdgeRelationID contains the ID of the +// edge and its relationship status between +// vertices. +type EdgeRelationID struct { + RelationID string `json:"relationId"` +} diff --git a/model/edgevalue.go b/model/edgevalue.go old mode 100644 new mode 100755 index f04cf41..ce0e1b0 --- a/model/edgevalue.go +++ b/model/edgevalue.go @@ -23,11 +23,18 @@ package model // EdgeValue contains the 'value' data // from the Edge object. type EdgeValue struct { - ID interface{} `json:"id"` + ID EdgeID `json:"id"` Label string `json:"label"` InVLabel string `json:"inVLabel,omitempty"` OutVLabel string `json:"outVLabel,omitempty"` - InV interface{} `json:"inV,omitempty"` - OutV interface{} `json:"outV,omitempty"` + InV EdgeVertex `json:"inV,omitempty"` + OutV EdgeVertex `json:"outV,omitempty"` Properties EdgeProperties `json:"properties,omitempty"` } + +// EdgeVertex only contains the type +// and ID of the vertex. +type EdgeVertex struct { + Type string `json:"@type"` + Value int64 `json:"@value"` +} diff --git a/model/idlist.go b/model/idlist.go old mode 100644 new mode 100755 index 44fc45e..0c10056 --- a/model/idlist.go +++ b/model/idlist.go @@ -26,7 +26,7 @@ import "encoding/json" // We use this instead of []ID for Gremlin v3.0 compatibility. type IDList struct { listOfIDs List - IDs []interface{} + IDs []ID } // UnmarshalJSON overrides to assure a proper unmarshal. diff --git a/model/unmarshal.go b/model/unmarshal.go old mode 100644 new mode 100755 index d250d14..532b802 --- a/model/unmarshal.go +++ b/model/unmarshal.go @@ -60,6 +60,23 @@ func UnmarshalEdgeList(data [][]byte) ([]Edge, error) { return list, nil } +// UnmarshalIDList is a utility to unmarshal a list +// or array of IDs properly. +func UnmarshalIDList(data [][]byte) ([]ID, error) { + var list []ID + + for _, res := range data { + var listPart IDList + if err := json.Unmarshal(res, &listPart); err != nil { + return nil, gremerror.NewUnmarshalError("UnmarshalIDList", res, err) + } + + list = append(list, listPart.IDs...) + } + + return list, nil +} + // UnmarshalPropertyList is a utility to unmarshal a list // or array of IDs properly. func UnmarshalPropertyList(data [][]byte) ([]Property, error) { diff --git a/model/vertex.go b/model/vertex.go old mode 100644 new mode 100755 index 4ca2c69..60c9720 --- a/model/vertex.go +++ b/model/vertex.go @@ -43,6 +43,7 @@ func NewVertex(label string, properties ...interface{}) Vertex { var v = Vertex{ Type: "g:Vertex", Value: VertexValue{ + ID: ID{}, Properties: make(PropertyMap), Label: label, }, @@ -76,8 +77,8 @@ func (v *Vertex) PropertyMap() PropertyMap { // ID will retrieve the Vertex ID for you // without having to traverse all the way through the structures. -func (v *Vertex) ID() interface{} { - return v.Value.ID +func (v *Vertex) ID() int64 { + return v.Value.ID.Value } // Label retrieves the label of the vertex diff --git a/model/vertex_query.go b/model/vertex_query.go old mode 100644 new mode 100755 index 34da14e..2554f65 --- a/model/vertex_query.go +++ b/model/vertex_query.go @@ -134,7 +134,7 @@ func (v *Vertex) QueryInEdges(client queryClient, labels ...string) ([]Edge, err // AddEdge adds an outgoing edge from this Vertex object to // another Vertex object via its unique ID. -func (v *Vertex) AddEdge(client queryClient, label string, outVID interface{}, properties ...interface{}) (Edge, error) { +func (v *Vertex) AddEdge(client queryClient, label string, outVID int64, properties ...interface{}) (Edge, error) { if client == nil { return Edge{}, gremerror.NewGrammesError("AddEdge", gremerror.ErrNilClient) } diff --git a/model/vertex_test.go b/model/vertex_test.go old mode 100644 new mode 100755 index 651b2b5..4788cee --- a/model/vertex_test.go +++ b/model/vertex_test.go @@ -28,11 +28,11 @@ import ( func TestVertexPropertyValue(t *testing.T) { Convey("Given a variable that represents the Vertex struct", t, func() { - testID := PropertyID{Value: "relID"} + testID := PropertyID{Value: PropertyIDValue{RelationID: "relID"}} testValue := ValueWrapper{PropertyDetailedValue: PropertyDetailedValue{Value: "tstInterface", Type: "pdvType"}} pi := Property{Type: "piType", Value: PropertyValue{ID: testID, Value: testValue, Label: "tstLabel"}} - pdmap := map[string][]Property{"testKey": {pi}} + pdmap := map[string][]Property{"testKey": []Property{pi}} v := Vertex{Type: "tesType", Value: VertexValue{Properties: pdmap}} @@ -47,12 +47,12 @@ func TestVertexPropertyValue(t *testing.T) { func TestVertexID(t *testing.T) { Convey("Given a variable that represents the Vertex struct", t, func() { - testID := PropertyID{Value: "relID"} + testID := PropertyID{Value: PropertyIDValue{RelationID: "relID"}} testValue := ValueWrapper{PropertyDetailedValue: PropertyDetailedValue{Value: "tstInterface", Type: "pdvType"}} pi := Property{Type: "piType", Value: PropertyValue{ID: testID, Value: testValue, Label: "tstLabel"}} - pdmap := map[string][]Property{"testKey": {pi}} + pdmap := map[string][]Property{"testKey": []Property{pi}} - v := Vertex{Type: "tesType", Value: VertexValue{Properties: pdmap, ID: 6789}} + v := Vertex{Type: "tesType", Value: VertexValue{Properties: pdmap, ID: ID{Value: 6789}}} Convey("When 'ID' is called with a string and int", func() { result := v.ID() @@ -65,12 +65,12 @@ func TestVertexID(t *testing.T) { func TestVertexLabel(t *testing.T) { Convey("Given a variable that represents the Vertex struct", t, func() { - testID := PropertyID{Value: "relID"} + testID := PropertyID{Value: PropertyIDValue{RelationID: "relID"}} testValue := ValueWrapper{PropertyDetailedValue: PropertyDetailedValue{Value: "tstInterface", Type: "pdvType"}} pi := Property{Type: "piType", Value: PropertyValue{ID: testID, Value: testValue, Label: "tstLabel"}} - pdmap := map[string][]Property{"testKey": {pi}} + pdmap := map[string][]Property{"testKey": []Property{pi}} - v := Vertex{Type: "tesType", Value: VertexValue{Label: "testLabel", ID: 6789, Properties: pdmap}} + v := Vertex{Type: "tesType", Value: VertexValue{Label: "testLabel", ID: ID{Value: 6789}, Properties: pdmap}} Convey("When 'Label' is called with a string and int", func() { result := v.Label() diff --git a/model/vertexid.go b/model/vertexid.go new file mode 100755 index 0000000..514c412 --- /dev/null +++ b/model/vertexid.go @@ -0,0 +1,28 @@ +// Copyright (c) 2018 Northwestern Mutual. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package model + +// ID contains the data stores in the +// 'ID' data including the type and Value +type ID struct { + Type string `json:"@type"` + Value int64 `json:"@value"` +} diff --git a/model/vertexproperty.go b/model/vertexproperty.go old mode 100644 new mode 100755 index 7e5ae0f..e6bbd5a --- a/model/vertexproperty.go +++ b/model/vertexproperty.go @@ -80,6 +80,12 @@ type PropertyValue struct { // PropertyID holds the ID that is used // for the property itself. type PropertyID struct { - Type string `json:"@type"` - Value interface{} `json:"@value"` + Type string `json:"@type"` + Value PropertyIDValue `json:"@value"` +} + +// PropertyIDValue holds the value +// of the PropertyID. +type PropertyIDValue struct { + RelationID string `json:"relationId"` } diff --git a/query/cardinality/cardinality.go b/query/cardinality/cardinality.go old mode 100644 new mode 100755 index 1a20e20..a57e293 --- a/query/cardinality/cardinality.go +++ b/query/cardinality/cardinality.go @@ -46,13 +46,13 @@ type Cardinality string const ( // List allows an arbitrary number of // values per element for such key. - List Cardinality = "list" + List Cardinality = "LIST" // Set allows multiple values but no // duplicate values per element for such key. - Set Cardinality = "set" + Set Cardinality = "SET" // Single allows at most one // value per element for such key - Single Cardinality = "single" + Single Cardinality = "SINGLE" ) // String will convert Cardinality to a string diff --git a/query/graph/makepropertykey_test.go b/query/graph/makepropertykey_test.go old mode 100644 new mode 100755 index 2cc6626..94d74cf --- a/query/graph/makepropertykey_test.go +++ b/query/graph/makepropertykey_test.go @@ -34,11 +34,13 @@ func TestMakePropertyKey(t *testing.T) { g := NewGraph() Convey("When 'MakePropertyKey' is called with a label string, DataType and Cardinality", func() { - var dt = datatype.String - var cr = cardinality.List + var dt datatype.DataType + dt = "String.class" + var cr cardinality.Cardinality + cr = "LIST" result := g.MakePropertyKey("labelTest", dt, cr) - Convey("Then result should equal 'graph.makePropertyKey('labelTest').dataType(String.class).cardinality(list)'", func() { - So(result.String(), ShouldEqual, "graph.makePropertyKey(\"labelTest\").dataType(String.class).cardinality(list)") + Convey("Then result should equal 'graph.makePropertyKey('labelTest').dataType(String.class).cardinality(LIST)'", func() { + So(result.String(), ShouldEqual, "graph.makePropertyKey(\"labelTest\").dataType(String.class).cardinality(LIST)") }) }) }) diff --git a/query/traversal/addproperty.go b/query/traversal/addproperty.go old mode 100644 new mode 100755 index feba93d..c87afd2 --- a/query/traversal/addproperty.go +++ b/query/traversal/addproperty.go @@ -20,6 +20,12 @@ package traversal +import ( + "strings" + + "github.com/northwesternmutual/grammes/query/cardinality" +) + // http://tinkerpop.apache.org/docs/current/reference/#addproperty-step // Property (sideEffect) unlike AddV() and AddE(), Property() is @@ -32,11 +38,42 @@ package traversal // Property(interface{} (Object), interface{} (Object), ...interface{} (Object)) // Property(Cardinality, string (Object), interface{} (Object), ...interface{} (Object)) func (g String) Property(objOrCard interface{}, obj interface{}, params ...interface{}) String { - fullParams := make([]interface{}, 0, len(params)+2) - fullParams = append(fullParams, objOrCard, obj) - fullParams = append(fullParams, params...) + g = g.append(".property(") + + switch objOrCard.(type) { + case cardinality.Cardinality: + g = g.append(objOrCard.(cardinality.Cardinality).String()) + case string: + g = g.append("\"" + objOrCard.(string) + "\"") + default: + g = g.append(fmtStr("%v", objOrCard)) + } + + switch obj.(type) { + case string: + g = g.append(",\"" + strings.ReplaceAll(obj.(string), "\"", "\\\"") + "\"") + case int64, uint64: + g = g.append(fmtStr(",%dL", obj)) + case float32, float64: + g = g.append(fmtStr(",%fd", obj)) + default: + g = g.append(fmtStr(",%v", obj)) + } + + if len(params) > 0 { + for _, p := range params { + switch p.(type) { + case string: + g = g.append(",\"" + strings.ReplaceAll(p.(string), "\"", "\\\"") + "\"") + case int64, uint64: + g = g.append(fmtStr(",%dL", p)) + default: + g = g.append(fmtStr(",%v", p)) + } + } + } - g.AddStep("property", fullParams...) + g = g.append(")") return g } diff --git a/query/traversal/addproperty_test.go b/query/traversal/addproperty_test.go old mode 100644 new mode 100755 index 8528010..f170f26 --- a/query/traversal/addproperty_test.go +++ b/query/traversal/addproperty_test.go @@ -38,8 +38,8 @@ func TestProperty(t *testing.T) { }) Convey("When 'Property' is called with object strings and cardinality", func() { result := g.Property(cardinality.Set, "obj1", "obj2") - Convey("Then result should equal 'g.property(set,'obj1','obj2')'", func() { - So(result.String(), ShouldEqual, "g.property(set,\"obj1\",\"obj2\")") + Convey("Then result should equal 'g.property(SET,'obj1','obj2')'", func() { + So(result.String(), ShouldEqual, "g.property(SET,\"obj1\",\"obj2\")") }) }) Convey("When 'Property' is called with object strings and ints", func() { diff --git a/query/traversal/graph.go b/query/traversal/graph.go old mode 100644 new mode 100755 index aea285a..3a95989 --- a/query/traversal/graph.go +++ b/query/traversal/graph.go @@ -28,8 +28,16 @@ package traversal // Signatures: // V() // V(int...) -func (g String) V(params ...interface{}) String { - g.AddStep("V", params...) +func (g String) V(params ...int) String { + // strParam := gatherInts(params...) + // g = g.append(fmtStr(".V(%v)", strParam)) + var p []interface{} + + for _, i := range params { + p = append(p, i) + } + + g.AddStep("V", p...) return g } diff --git a/query/traversal/to.go b/query/traversal/to.go old mode 100644 new mode 100755 index 24db25b..d03144d --- a/query/traversal/to.go +++ b/query/traversal/to.go @@ -83,7 +83,7 @@ func (g String) ToV(dir direction.Direction) String { // ToVId can be used to make a string query that will take a vertex id as a parameter, // and can be used to point an edge towards this vertex ID. -func (g String) ToVId(vertexID interface{}) String { +func (g String) ToVId(vertexID int64) String { g = g.append(fmtStr(".to(V().hasId(%v))", vertexID)) return g diff --git a/query/traversal/util.go b/query/traversal/util.go old mode 100644 new mode 100755 diff --git a/quick/dropvertex.go b/quick/dropvertex.go old mode 100644 new mode 100755 index 0b064cd..bcdf600 --- a/quick/dropvertex.go +++ b/quick/dropvertex.go @@ -43,7 +43,7 @@ func DropVertexLabel(host, label string) error { // DropVertexByID will search for vertices with the // provided IDs and drop them if such vertices exist. -func DropVertexByID(host string, ids ...interface{}) error { +func DropVertexByID(host string, ids ...int64) error { err := checkForClient(host) if err != nil { return err diff --git a/quick/getvertex.go b/quick/getvertex.go old mode 100644 new mode 100755 index 3a9b9b6..8982f76 --- a/quick/getvertex.go +++ b/quick/getvertex.go @@ -64,7 +64,7 @@ func AllVertices(host string) ([]grammes.Vertex, error) { // ID assigned to it. This ID is unique to every // vertex on the graph. This is the best way of finding // vertices without any conflicting labels or properties. -func VertexByID(host string, id interface{}) (grammes.Vertex, error) { +func VertexByID(host string, id int64) (grammes.Vertex, error) { err := checkForClient(host) if err != nil { return nilVertex, err diff --git a/quick/misc.go b/quick/misc.go old mode 100644 new mode 100755 index 1116a70..c0f7385 --- a/quick/misc.go +++ b/quick/misc.go @@ -38,7 +38,7 @@ func DropAll(host string) error { // SetVertexProperty will search the graph for a vertex // with the given ID and set the properties provided. -func SetVertexProperty(host string, id interface{}, properties ...interface{}) error { +func SetVertexProperty(host string, id int64, properties ...interface{}) error { err := checkForClient(host) if err != nil { return err diff --git a/quick/schema.go b/quick/schema.go old mode 100644 new mode 100755 index 80353b0..93e94f2 --- a/quick/schema.go +++ b/quick/schema.go @@ -29,7 +29,7 @@ import ( // AddEdgeLabel adds the edge label to the // graph directly. This method returns the schema id // of the edge label added. -func AddEdgeLabel(multi multiplicity.Multiplicity, host, label string) (interface{}, error) { +func AddEdgeLabel(multi multiplicity.Multiplicity, host, label string) (int64, error) { err := checkForClient(host) if err != nil { return 0, err @@ -48,7 +48,7 @@ func AddEdgeLabel(multi multiplicity.Multiplicity, host, label string) (interfac // but with the ability to do multiple labels at a // time. This function is called similarly to your // favorite logger. -func AddEdgeLabels(host string, multiplicityAndLabels ...interface{}) ([]interface{}, error) { +func AddEdgeLabels(host string, multiplicityAndLabels ...interface{}) ([]int64, error) { err := checkForClient(host) if err != nil { return nil, err @@ -66,7 +66,7 @@ func AddEdgeLabels(host string, multiplicityAndLabels ...interface{}) ([]interfa // AddPropertyKey adds the edge label to the // graph directly. This method returns the schema id // of the edge label added. -func AddPropertyKey(host, propertyName string, datatype datatype.DataType, cardinality cardinality.Cardinality) (interface{}, error) { +func AddPropertyKey(host, propertyName string, datatype datatype.DataType, cardinality cardinality.Cardinality) (int64, error) { err := checkForClient(host) if err != nil { return 0, err diff --git a/quick/util.go b/quick/util.go old mode 100644 new mode 100755 index 342e80e..9edf435 --- a/quick/util.go +++ b/quick/util.go @@ -21,10 +21,10 @@ package quick import ( - "github.com/northwesternmutual/grammes" - "github.com/northwesternmutual/grammes/logging" - "github.com/northwesternmutual/grammes/query/graph" - "github.com/northwesternmutual/grammes/query/traversal" + "gitlab.com/kaleidoscope.root/grammes-gremlin/grammes" + "gitlab.com/kaleidoscope.root/grammes-gremlin/grammes/logging" + "gitlab.com/kaleidoscope.root/grammes-gremlin/grammes/query/graph" + "gitlab.com/kaleidoscope.root/grammes-gremlin/grammes/query/traversal" ) // CustomTraversal is have a custom prefix for your diff --git a/quick/vertexid.go b/quick/vertexid.go old mode 100644 new mode 100755 index 7c22fb2..edee983 --- a/quick/vertexid.go +++ b/quick/vertexid.go @@ -24,8 +24,8 @@ import "github.com/northwesternmutual/grammes/query" // VertexIDsByQuery will take a query and execute it. Then it will // run through and extract all the vertex IDs matching the -// traversal and return them in an array. -func VertexIDsByQuery(host string, q query.Query) ([]interface{}, error) { +// traversal and return them in an array of int64. +func VertexIDsByQuery(host string, q query.Query) ([]int64, error) { err := checkForClient(host) if err != nil { return nil, err @@ -42,7 +42,7 @@ func VertexIDsByQuery(host string, q query.Query) ([]interface{}, error) { // VertexIDs takes the label and optional properties to retrieve // the IDs desired from the graph. -func VertexIDs(host, label string, properties ...interface{}) ([]interface{}, error) { +func VertexIDs(host, label string, properties ...interface{}) ([]int64, error) { err := checkForClient(host) if err != nil { return nil, err From 2dce5984cf8be6d0212df90545a7d3c0c9a6a736 Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Wed, 4 Jan 2023 18:26:47 +0500 Subject: [PATCH 03/16] missed one --- quick/util.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/quick/util.go b/quick/util.go index 9edf435..342e80e 100755 --- a/quick/util.go +++ b/quick/util.go @@ -21,10 +21,10 @@ package quick import ( - "gitlab.com/kaleidoscope.root/grammes-gremlin/grammes" - "gitlab.com/kaleidoscope.root/grammes-gremlin/grammes/logging" - "gitlab.com/kaleidoscope.root/grammes-gremlin/grammes/query/graph" - "gitlab.com/kaleidoscope.root/grammes-gremlin/grammes/query/traversal" + "github.com/northwesternmutual/grammes" + "github.com/northwesternmutual/grammes/logging" + "github.com/northwesternmutual/grammes/query/graph" + "github.com/northwesternmutual/grammes/query/traversal" ) // CustomTraversal is have a custom prefix for your From f638a134efd1954df4533aaf7b4771cb242c3290 Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Thu, 5 Jan 2023 12:04:49 +0500 Subject: [PATCH 04/16] changing from zap int64 to zap any --- examples/add-vertex-by-api/main.go | 4 ++-- examples/add-vertex-by-query/main.go | 2 +- examples/add-vertex-by-string/main.go | 2 +- examples/add-vertex-by-struct/main.go | 2 +- examples/add-vertex/main.go | 2 +- examples/all-vertices/main.go | 2 +- examples/concurrent-example/main.go | 2 +- examples/drop-all/main.go | 4 ++-- examples/drop-vertex-by-id/main.go | 2 +- examples/drop-vertex-by-query/main.go | 2 +- examples/drop-vertex-by-string/main.go | 2 +- examples/drop-vertex-label/main.go | 2 +- examples/id-by-label/main.go | 2 +- examples/id-by-property/main.go | 2 +- examples/id-by-query/main.go | 2 +- examples/id-by-string/main.go | 2 +- examples/testing/main.go | 2 +- examples/vertex-by-id/main.go | 2 +- examples/vertex-count/main.go | 2 +- examples/vertex-edge-example/main.go | 4 ++-- examples/vertices-by-label/main.go | 2 +- examples/vertices-by-property/main.go | 2 +- examples/vertices-by-query/main.go | 2 +- examples/vertices-by-string/main.go | 2 +- 24 files changed, 27 insertions(+), 27 deletions(-) diff --git a/examples/add-vertex-by-api/main.go b/examples/add-vertex-by-api/main.go index 1f273cc..f593ee1 100644 --- a/examples/add-vertex-by-api/main.go +++ b/examples/add-vertex-by-api/main.go @@ -80,7 +80,7 @@ func main() { logger.Fatal("Failed to count vertices", zap.Error(err)) } - logger.Info("Number of Vertices Before", zap.Int64("count", count)) + logger.Info("Number of Vertices Before", zap.Any("count", count)) // Read the request example JSON from the assets/ folder. api, err := prepareAPI("../../assets/test/request.json") @@ -108,5 +108,5 @@ func main() { logger.Fatal("Failed to count vertices", zap.Error(err)) } - logger.Info("Number of Vertices After", zap.Int64("count", count)) + logger.Info("Number of Vertices After", zap.Any("count", count)) } diff --git a/examples/add-vertex-by-query/main.go b/examples/add-vertex-by-query/main.go index ed10792..c7e1fdd 100644 --- a/examples/add-vertex-by-query/main.go +++ b/examples/add-vertex-by-query/main.go @@ -81,5 +81,5 @@ func main() { // Print out the number of vertices on the graph. // This should be 1. - logger.Info("Counted Vertices", zap.Int64("count", count)) + logger.Info("Counted Vertices", zap.Any("count", count)) } diff --git a/examples/add-vertex-by-string/main.go b/examples/add-vertex-by-string/main.go index 6fcaabb..00e963c 100644 --- a/examples/add-vertex-by-string/main.go +++ b/examples/add-vertex-by-string/main.go @@ -78,5 +78,5 @@ func main() { // Print out the number of vertices on the graph. // This should be 1. - logger.Info("Counted Vertices", zap.Int64("count", count)) + logger.Info("Counted Vertices", zap.Any("count", count)) } diff --git a/examples/add-vertex-by-struct/main.go b/examples/add-vertex-by-struct/main.go index ea6511d..e6c83a8 100755 --- a/examples/add-vertex-by-struct/main.go +++ b/examples/add-vertex-by-struct/main.go @@ -70,7 +70,7 @@ func main() { // Print out the resulting vertex and its values. logger.Info("Vertex", zap.String("label", vertex.Label())) - logger.Info("Vertex", zap.Int64("ID", vertex.ID())) + logger.Info("Vertex", zap.Any("ID", vertex.ID())) for k, v := range vertex.PropertyMap() { logger.Info("Property", zap.Any(k, v[0].GetValue())) diff --git a/examples/add-vertex/main.go b/examples/add-vertex/main.go index 74d7fa6..db7de26 100644 --- a/examples/add-vertex/main.go +++ b/examples/add-vertex/main.go @@ -84,5 +84,5 @@ func main() { // Print out the number of vertices on the graph. // This should be 1. - logger.Info("Counted Vertices", zap.Int64("count", count)) + logger.Info("Counted Vertices", zap.Any("count", count)) } diff --git a/examples/all-vertices/main.go b/examples/all-vertices/main.go index 46581d0..d0277ee 100755 --- a/examples/all-vertices/main.go +++ b/examples/all-vertices/main.go @@ -73,7 +73,7 @@ func main() { for _, vertex := range vertices { logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Int64("id", vertex.ID()), + zap.Any("id", vertex.ID()), ) } } diff --git a/examples/concurrent-example/main.go b/examples/concurrent-example/main.go index 7e4d839..dab4d03 100644 --- a/examples/concurrent-example/main.go +++ b/examples/concurrent-example/main.go @@ -73,5 +73,5 @@ func main() { } // Log the count of the vertices. - logger.Info("Counted vertices", zap.Int64("count", count)) + logger.Info("Counted vertices", zap.Any("count", count)) } diff --git a/examples/drop-all/main.go b/examples/drop-all/main.go index 05756a2..5877570 100644 --- a/examples/drop-all/main.go +++ b/examples/drop-all/main.go @@ -66,7 +66,7 @@ func main() { } // Log the amount of vertices that are now on the graph. - logger.Info("Counted vertices", zap.Int64("count", count)) + logger.Info("Counted vertices", zap.Any("count", count)) // Now drop all of the vertices. client.DropAll() @@ -78,5 +78,5 @@ func main() { } // Log the amount of vertices that are now on the graph. - logger.Info("Counted vertices", zap.Int64("count", count)) + logger.Info("Counted vertices", zap.Any("count", count)) } diff --git a/examples/drop-vertex-by-id/main.go b/examples/drop-vertex-by-id/main.go index 42f83b7..7d7f04e 100644 --- a/examples/drop-vertex-by-id/main.go +++ b/examples/drop-vertex-by-id/main.go @@ -81,5 +81,5 @@ func main() { // Print out the vertices that are left over after dropping. // This should be 2. - logger.Info("vertices left over (should be 2)", zap.Int64("count", count)) + logger.Info("vertices left over (should be 2)", zap.Any("count", count)) } diff --git a/examples/drop-vertex-by-query/main.go b/examples/drop-vertex-by-query/main.go index 50c2e0a..e0c5ebd 100644 --- a/examples/drop-vertex-by-query/main.go +++ b/examples/drop-vertex-by-query/main.go @@ -80,5 +80,5 @@ func main() { // Print out the vertices that are left over after dropping. // This should be 1. - logger.Info("vertices left over", zap.Int64("count", count)) + logger.Info("vertices left over", zap.Any("count", count)) } diff --git a/examples/drop-vertex-by-string/main.go b/examples/drop-vertex-by-string/main.go index 332545a..45c00b3 100644 --- a/examples/drop-vertex-by-string/main.go +++ b/examples/drop-vertex-by-string/main.go @@ -77,5 +77,5 @@ func main() { // Print out the vertices that are left over after dropping. // This should be 1. - logger.Info("vertices left over", zap.Int64("count", count)) + logger.Info("vertices left over", zap.Any("count", count)) } diff --git a/examples/drop-vertex-label/main.go b/examples/drop-vertex-label/main.go index 7621739..26a7b86 100644 --- a/examples/drop-vertex-label/main.go +++ b/examples/drop-vertex-label/main.go @@ -78,5 +78,5 @@ func main() { // Print out the vertices that are left over after dropping. // This should be 1. - logger.Info("vertices left over", zap.Int64("count", count)) + logger.Info("vertices left over", zap.Any("count", count)) } diff --git a/examples/id-by-label/main.go b/examples/id-by-label/main.go index a266f6f..3cf8172 100755 --- a/examples/id-by-label/main.go +++ b/examples/id-by-label/main.go @@ -73,6 +73,6 @@ func main() { // Print out all the received vertex IDs. // This should only print out one ID. for _, id := range ids { - logger.Info("vertex id", zap.Int64("value", id)) + logger.Info("vertex id", zap.Any("value", id)) } } diff --git a/examples/id-by-property/main.go b/examples/id-by-property/main.go index 9d10a81..37e3dfa 100755 --- a/examples/id-by-property/main.go +++ b/examples/id-by-property/main.go @@ -74,6 +74,6 @@ func main() { // Print out all the received vertex IDs. // This should only print out one ID. for _, id := range ids { - logger.Info("vertex id", zap.Int64("value", id)) + logger.Info("vertex id", zap.Any("value", id)) } } diff --git a/examples/id-by-query/main.go b/examples/id-by-query/main.go index 7f77a2d..1fba6b1 100755 --- a/examples/id-by-query/main.go +++ b/examples/id-by-query/main.go @@ -75,6 +75,6 @@ func main() { // Print out all the received vertex IDs. for _, id := range ids { - logger.Info("vertex id", zap.Int64("value", id)) + logger.Info("vertex id", zap.Any("value", id)) } } diff --git a/examples/id-by-string/main.go b/examples/id-by-string/main.go index 2f06aaa..3849ffc 100755 --- a/examples/id-by-string/main.go +++ b/examples/id-by-string/main.go @@ -72,6 +72,6 @@ func main() { // Print out all the received vertex IDs. for _, id := range ids { - logger.Info("vertex id", zap.Int64("value", id)) + logger.Info("vertex id", zap.Any("value", id)) } } diff --git a/examples/testing/main.go b/examples/testing/main.go index 99b5b58..94847ae 100644 --- a/examples/testing/main.go +++ b/examples/testing/main.go @@ -71,7 +71,7 @@ func main() { } // Log the count of the vertices. - logger.Info("Counted vertices", zap.Int64("count", count)) + logger.Info("Counted vertices", zap.Any("count", count)) vertices, err := client.AllVertices() if err != nil { diff --git a/examples/vertex-by-id/main.go b/examples/vertex-by-id/main.go index fad65f9..9dda5bd 100755 --- a/examples/vertex-by-id/main.go +++ b/examples/vertex-by-id/main.go @@ -78,6 +78,6 @@ func main() { // Print out the received vertex. logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Int64("id", vertex.ID()), + zap.Any("id", vertex.ID()), ) } diff --git a/examples/vertex-count/main.go b/examples/vertex-count/main.go index 6b69de3..ec283da 100644 --- a/examples/vertex-count/main.go +++ b/examples/vertex-count/main.go @@ -69,5 +69,5 @@ func main() { logger.Fatal("Couldn't gather all IDs", zap.Error(err)) } - logger.Info("Counted vertices", zap.Int64("count", count)) + logger.Info("Counted vertices", zap.Any("count", count)) } diff --git a/examples/vertex-edge-example/main.go b/examples/vertex-edge-example/main.go index 3c7a37a..9c88f9b 100755 --- a/examples/vertex-edge-example/main.go +++ b/examples/vertex-edge-example/main.go @@ -123,13 +123,13 @@ func printEdges(client *grammes.Client, edges []grammes.Edge) { ) logger.Info("OutVertex", - zap.Int64("ID", edges[0].OutVertexID()), + zap.Any("ID", edges[0].OutVertexID()), zap.String("Label", edges[0].OutVertexLabel()), zap.Any("Name", v1.PropertyValue("name", 0)), ) logger.Info("InVertex", - zap.Int64("ID", edges[0].InVertexID()), + zap.Any("ID", edges[0].InVertexID()), zap.String("Label", edges[0].InVertexLabel()), zap.Any("Name", v2.PropertyValue("name", 0)), ) diff --git a/examples/vertices-by-label/main.go b/examples/vertices-by-label/main.go index a29354e..7d54c29 100755 --- a/examples/vertices-by-label/main.go +++ b/examples/vertices-by-label/main.go @@ -74,7 +74,7 @@ func main() { for _, vertex := range vertices { logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Int64("id", vertex.ID()), + zap.Any("id", vertex.ID()), ) } } diff --git a/examples/vertices-by-property/main.go b/examples/vertices-by-property/main.go index e7e4fb5..4a6bd5e 100755 --- a/examples/vertices-by-property/main.go +++ b/examples/vertices-by-property/main.go @@ -74,7 +74,7 @@ func main() { for _, vertex := range vertices { logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Int64("id", vertex.ID()), + zap.Any("id", vertex.ID()), zap.Any("name", vertex.PropertyValue("name", 0)), ) } diff --git a/examples/vertices-by-query/main.go b/examples/vertices-by-query/main.go index 91c4b2b..8d339c1 100755 --- a/examples/vertices-by-query/main.go +++ b/examples/vertices-by-query/main.go @@ -76,7 +76,7 @@ func main() { for _, vertex := range vertices { logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Int64("id", vertex.ID()), + zap.Any("id", vertex.ID()), ) } } diff --git a/examples/vertices-by-string/main.go b/examples/vertices-by-string/main.go index fc72658..2758a2c 100755 --- a/examples/vertices-by-string/main.go +++ b/examples/vertices-by-string/main.go @@ -73,7 +73,7 @@ func main() { for _, vertex := range vertices { logger.Info("gathered vertex", zap.String("label", vertex.Label()), - zap.Int64("id", vertex.ID()), + zap.Any("id", vertex.ID()), ) } } From 4cd0f1ba359ef32af8aa631dbde964c09e1df9e1 Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Thu, 5 Jan 2023 12:11:38 +0500 Subject: [PATCH 05/16] some more zaps --- examples/add-vertex-by-api/main.go | 4 ++-- examples/add-vertex-by-query/main.go | 2 +- examples/add-vertex-by-string/main.go | 2 +- examples/add-vertex/main.go | 2 +- examples/concurrent-example/main.go | 2 +- examples/drop-all/main.go | 4 ++-- examples/drop-vertex-by-id/main.go | 2 +- examples/drop-vertex-by-query/main.go | 2 +- examples/drop-vertex-by-string/main.go | 2 +- examples/drop-vertex-label/main.go | 2 +- examples/testing/main.go | 2 +- examples/vertex-count/main.go | 2 +- examples/vertex-edge-example/main.go | 5 +---- 13 files changed, 15 insertions(+), 18 deletions(-) diff --git a/examples/add-vertex-by-api/main.go b/examples/add-vertex-by-api/main.go index f593ee1..1f273cc 100644 --- a/examples/add-vertex-by-api/main.go +++ b/examples/add-vertex-by-api/main.go @@ -80,7 +80,7 @@ func main() { logger.Fatal("Failed to count vertices", zap.Error(err)) } - logger.Info("Number of Vertices Before", zap.Any("count", count)) + logger.Info("Number of Vertices Before", zap.Int64("count", count)) // Read the request example JSON from the assets/ folder. api, err := prepareAPI("../../assets/test/request.json") @@ -108,5 +108,5 @@ func main() { logger.Fatal("Failed to count vertices", zap.Error(err)) } - logger.Info("Number of Vertices After", zap.Any("count", count)) + logger.Info("Number of Vertices After", zap.Int64("count", count)) } diff --git a/examples/add-vertex-by-query/main.go b/examples/add-vertex-by-query/main.go index c7e1fdd..ed10792 100644 --- a/examples/add-vertex-by-query/main.go +++ b/examples/add-vertex-by-query/main.go @@ -81,5 +81,5 @@ func main() { // Print out the number of vertices on the graph. // This should be 1. - logger.Info("Counted Vertices", zap.Any("count", count)) + logger.Info("Counted Vertices", zap.Int64("count", count)) } diff --git a/examples/add-vertex-by-string/main.go b/examples/add-vertex-by-string/main.go index 00e963c..6fcaabb 100644 --- a/examples/add-vertex-by-string/main.go +++ b/examples/add-vertex-by-string/main.go @@ -78,5 +78,5 @@ func main() { // Print out the number of vertices on the graph. // This should be 1. - logger.Info("Counted Vertices", zap.Any("count", count)) + logger.Info("Counted Vertices", zap.Int64("count", count)) } diff --git a/examples/add-vertex/main.go b/examples/add-vertex/main.go index db7de26..74d7fa6 100644 --- a/examples/add-vertex/main.go +++ b/examples/add-vertex/main.go @@ -84,5 +84,5 @@ func main() { // Print out the number of vertices on the graph. // This should be 1. - logger.Info("Counted Vertices", zap.Any("count", count)) + logger.Info("Counted Vertices", zap.Int64("count", count)) } diff --git a/examples/concurrent-example/main.go b/examples/concurrent-example/main.go index dab4d03..7e4d839 100644 --- a/examples/concurrent-example/main.go +++ b/examples/concurrent-example/main.go @@ -73,5 +73,5 @@ func main() { } // Log the count of the vertices. - logger.Info("Counted vertices", zap.Any("count", count)) + logger.Info("Counted vertices", zap.Int64("count", count)) } diff --git a/examples/drop-all/main.go b/examples/drop-all/main.go index 5877570..05756a2 100644 --- a/examples/drop-all/main.go +++ b/examples/drop-all/main.go @@ -66,7 +66,7 @@ func main() { } // Log the amount of vertices that are now on the graph. - logger.Info("Counted vertices", zap.Any("count", count)) + logger.Info("Counted vertices", zap.Int64("count", count)) // Now drop all of the vertices. client.DropAll() @@ -78,5 +78,5 @@ func main() { } // Log the amount of vertices that are now on the graph. - logger.Info("Counted vertices", zap.Any("count", count)) + logger.Info("Counted vertices", zap.Int64("count", count)) } diff --git a/examples/drop-vertex-by-id/main.go b/examples/drop-vertex-by-id/main.go index 7d7f04e..42f83b7 100644 --- a/examples/drop-vertex-by-id/main.go +++ b/examples/drop-vertex-by-id/main.go @@ -81,5 +81,5 @@ func main() { // Print out the vertices that are left over after dropping. // This should be 2. - logger.Info("vertices left over (should be 2)", zap.Any("count", count)) + logger.Info("vertices left over (should be 2)", zap.Int64("count", count)) } diff --git a/examples/drop-vertex-by-query/main.go b/examples/drop-vertex-by-query/main.go index e0c5ebd..50c2e0a 100644 --- a/examples/drop-vertex-by-query/main.go +++ b/examples/drop-vertex-by-query/main.go @@ -80,5 +80,5 @@ func main() { // Print out the vertices that are left over after dropping. // This should be 1. - logger.Info("vertices left over", zap.Any("count", count)) + logger.Info("vertices left over", zap.Int64("count", count)) } diff --git a/examples/drop-vertex-by-string/main.go b/examples/drop-vertex-by-string/main.go index 45c00b3..332545a 100644 --- a/examples/drop-vertex-by-string/main.go +++ b/examples/drop-vertex-by-string/main.go @@ -77,5 +77,5 @@ func main() { // Print out the vertices that are left over after dropping. // This should be 1. - logger.Info("vertices left over", zap.Any("count", count)) + logger.Info("vertices left over", zap.Int64("count", count)) } diff --git a/examples/drop-vertex-label/main.go b/examples/drop-vertex-label/main.go index 26a7b86..7621739 100644 --- a/examples/drop-vertex-label/main.go +++ b/examples/drop-vertex-label/main.go @@ -78,5 +78,5 @@ func main() { // Print out the vertices that are left over after dropping. // This should be 1. - logger.Info("vertices left over", zap.Any("count", count)) + logger.Info("vertices left over", zap.Int64("count", count)) } diff --git a/examples/testing/main.go b/examples/testing/main.go index 94847ae..99b5b58 100644 --- a/examples/testing/main.go +++ b/examples/testing/main.go @@ -71,7 +71,7 @@ func main() { } // Log the count of the vertices. - logger.Info("Counted vertices", zap.Any("count", count)) + logger.Info("Counted vertices", zap.Int64("count", count)) vertices, err := client.AllVertices() if err != nil { diff --git a/examples/vertex-count/main.go b/examples/vertex-count/main.go index ec283da..6b69de3 100644 --- a/examples/vertex-count/main.go +++ b/examples/vertex-count/main.go @@ -69,5 +69,5 @@ func main() { logger.Fatal("Couldn't gather all IDs", zap.Error(err)) } - logger.Info("Counted vertices", zap.Any("count", count)) + logger.Info("Counted vertices", zap.Int64("count", count)) } diff --git a/examples/vertex-edge-example/main.go b/examples/vertex-edge-example/main.go index 9c88f9b..8640a76 100755 --- a/examples/vertex-edge-example/main.go +++ b/examples/vertex-edge-example/main.go @@ -114,20 +114,17 @@ func printEdges(client *grammes.Client, edges []grammes.Edge) { } // Print the information about the edge including // its ID, label, and its properties. - logger.Info("Edge", - zap.String("ID", edges[0].ID()), + zap.Any("ID", edges[0].ID()), zap.String("Label", edges[0].Label()), zap.Any("ageDiff", edges[0].PropertyValue("ageDiff")), zap.Any("driveDist", edges[0].PropertyValue("driveDist")), ) - logger.Info("OutVertex", zap.Any("ID", edges[0].OutVertexID()), zap.String("Label", edges[0].OutVertexLabel()), zap.Any("Name", v1.PropertyValue("name", 0)), ) - logger.Info("InVertex", zap.Any("ID", edges[0].InVertexID()), zap.String("Label", edges[0].InVertexLabel()), From 367eec7fa60bf42d705b7bbf836893be777f0810 Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Thu, 5 Jan 2023 12:13:27 +0500 Subject: [PATCH 06/16] whitespaces --- examples/vertex-edge-example/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/vertex-edge-example/main.go b/examples/vertex-edge-example/main.go index 8640a76..d512401 100755 --- a/examples/vertex-edge-example/main.go +++ b/examples/vertex-edge-example/main.go @@ -114,17 +114,20 @@ func printEdges(client *grammes.Client, edges []grammes.Edge) { } // Print the information about the edge including // its ID, label, and its properties. + logger.Info("Edge", zap.Any("ID", edges[0].ID()), zap.String("Label", edges[0].Label()), zap.Any("ageDiff", edges[0].PropertyValue("ageDiff")), zap.Any("driveDist", edges[0].PropertyValue("driveDist")), ) + logger.Info("OutVertex", zap.Any("ID", edges[0].OutVertexID()), zap.String("Label", edges[0].OutVertexLabel()), zap.Any("Name", v1.PropertyValue("name", 0)), ) + logger.Info("InVertex", zap.Any("ID", edges[0].InVertexID()), zap.String("Label", edges[0].InVertexLabel()), From 3bc5d2b9f46a92865608ceedbb2c5a7707f33a62 Mon Sep 17 00:00:00 2001 From: Zubair Nabi Date: Fri, 13 Jan 2023 09:19:41 +0500 Subject: [PATCH 07/16] Removing superflous files from PR. --- examples/add-vertex-by-struct/main.go | 0 examples/all-vertices/main.go | 0 examples/id-by-label/main.go | 0 examples/id-by-property/main.go | 0 examples/id-by-query/main.go | 0 examples/id-by-string/main.go | 0 examples/vertex-by-id/main.go | 0 examples/vertex-edge-example/main.go | 3 --- examples/vertices-by-label/main.go | 0 examples/vertices-by-property/main.go | 0 examples/vertices-by-query/main.go | 0 examples/vertices-by-string/main.go | 0 12 files changed, 3 deletions(-) mode change 100755 => 100644 examples/add-vertex-by-struct/main.go mode change 100755 => 100644 examples/all-vertices/main.go mode change 100755 => 100644 examples/id-by-label/main.go mode change 100755 => 100644 examples/id-by-property/main.go mode change 100755 => 100644 examples/id-by-query/main.go mode change 100755 => 100644 examples/id-by-string/main.go mode change 100755 => 100644 examples/vertex-by-id/main.go mode change 100755 => 100644 examples/vertices-by-label/main.go mode change 100755 => 100644 examples/vertices-by-property/main.go mode change 100755 => 100644 examples/vertices-by-query/main.go mode change 100755 => 100644 examples/vertices-by-string/main.go diff --git a/examples/add-vertex-by-struct/main.go b/examples/add-vertex-by-struct/main.go old mode 100755 new mode 100644 diff --git a/examples/all-vertices/main.go b/examples/all-vertices/main.go old mode 100755 new mode 100644 diff --git a/examples/id-by-label/main.go b/examples/id-by-label/main.go old mode 100755 new mode 100644 diff --git a/examples/id-by-property/main.go b/examples/id-by-property/main.go old mode 100755 new mode 100644 diff --git a/examples/id-by-query/main.go b/examples/id-by-query/main.go old mode 100755 new mode 100644 diff --git a/examples/id-by-string/main.go b/examples/id-by-string/main.go old mode 100755 new mode 100644 diff --git a/examples/vertex-by-id/main.go b/examples/vertex-by-id/main.go old mode 100755 new mode 100644 diff --git a/examples/vertex-edge-example/main.go b/examples/vertex-edge-example/main.go index d512401..8640a76 100755 --- a/examples/vertex-edge-example/main.go +++ b/examples/vertex-edge-example/main.go @@ -114,20 +114,17 @@ func printEdges(client *grammes.Client, edges []grammes.Edge) { } // Print the information about the edge including // its ID, label, and its properties. - logger.Info("Edge", zap.Any("ID", edges[0].ID()), zap.String("Label", edges[0].Label()), zap.Any("ageDiff", edges[0].PropertyValue("ageDiff")), zap.Any("driveDist", edges[0].PropertyValue("driveDist")), ) - logger.Info("OutVertex", zap.Any("ID", edges[0].OutVertexID()), zap.String("Label", edges[0].OutVertexLabel()), zap.Any("Name", v1.PropertyValue("name", 0)), ) - logger.Info("InVertex", zap.Any("ID", edges[0].InVertexID()), zap.String("Label", edges[0].InVertexLabel()), diff --git a/examples/vertices-by-label/main.go b/examples/vertices-by-label/main.go old mode 100755 new mode 100644 diff --git a/examples/vertices-by-property/main.go b/examples/vertices-by-property/main.go old mode 100755 new mode 100644 diff --git a/examples/vertices-by-query/main.go b/examples/vertices-by-query/main.go old mode 100755 new mode 100644 diff --git a/examples/vertices-by-string/main.go b/examples/vertices-by-string/main.go old mode 100755 new mode 100644 From e41aa733a9936ea0d37daed3ddc4f6fd0364b867 Mon Sep 17 00:00:00 2001 From: Zubair Nabi Date: Fri, 13 Jan 2023 11:04:52 +0500 Subject: [PATCH 08/16] Removing another superflous file. --- quick/getvertex.go | 2 +- quick/util.go | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 quick/getvertex.go mode change 100755 => 100644 quick/util.go diff --git a/quick/getvertex.go b/quick/getvertex.go old mode 100755 new mode 100644 index 8982f76..3a9b9b6 --- a/quick/getvertex.go +++ b/quick/getvertex.go @@ -64,7 +64,7 @@ func AllVertices(host string) ([]grammes.Vertex, error) { // ID assigned to it. This ID is unique to every // vertex on the graph. This is the best way of finding // vertices without any conflicting labels or properties. -func VertexByID(host string, id int64) (grammes.Vertex, error) { +func VertexByID(host string, id interface{}) (grammes.Vertex, error) { err := checkForClient(host) if err != nil { return nilVertex, err diff --git a/quick/util.go b/quick/util.go old mode 100755 new mode 100644 From bc9bda3b39c0383caa3b162042dd4e2bcb16fdfe Mon Sep 17 00:00:00 2001 From: Zubair Nabi Date: Fri, 13 Jan 2023 12:42:09 +0500 Subject: [PATCH 09/16] Syncing with upstream. --- examples/vertex-edge-example/main.go | 5 +++- gremconnect/response.go | 25 ++++++++--------- gremconnect/response_test.go | 19 ++++++------- gremerror/networkerror.go | 5 +++- manager/addvertex_test.go | 19 +++++-------- manager/dropvertex.go | 8 +++--- manager/getvertex.go | 5 ++-- manager/misc.go | 40 +++++++++++++++++----------- manager/model.go | 24 ++++++++--------- manager/model_test.go | 4 +-- manager/schema.go | 8 +++--- manager/vertexid.go | 12 ++++----- model.go | 11 -------- model/edge.go | 12 ++++----- model/edge_test.go | 12 ++++----- model/edgeid.go | 35 ------------------------ model/edgevalue.go | 13 +++------ model/idlist.go | 2 +- model/unmarshal.go | 17 ------------ model/vertex.go | 5 ++-- model/vertex_query.go | 2 +- model/vertex_test.go | 16 +++++------ model/vertexid.go | 28 ------------------- model/vertexproperty.go | 10 ++----- query/cardinality/cardinality.go | 6 ++--- query/graph/makepropertykey_test.go | 10 +++---- query/traversal/addproperty_test.go | 4 +-- query/traversal/pagerank_test.go | 4 +-- query/traversal/skip_test.go | 4 +-- query/traversal/timeLimit_test.go | 4 +-- query/traversal/to.go | 2 +- query/traversal/util_test.go | 6 ++--- query/traversal/withsack_test.go | 4 +-- quick/dropvertex.go | 2 +- quick/misc.go | 2 +- quick/schema.go | 6 ++--- quick/vertexid.go | 6 ++--- 37 files changed, 150 insertions(+), 247 deletions(-) mode change 100755 => 100644 examples/vertex-edge-example/main.go mode change 100755 => 100644 gremconnect/response.go mode change 100755 => 100644 gremconnect/response_test.go mode change 100755 => 100644 gremerror/networkerror.go mode change 100755 => 100644 manager/addvertex_test.go mode change 100755 => 100644 manager/dropvertex.go mode change 100755 => 100644 manager/getvertex.go mode change 100755 => 100644 manager/misc.go mode change 100755 => 100644 manager/model.go mode change 100755 => 100644 manager/model_test.go mode change 100755 => 100644 manager/schema.go mode change 100755 => 100644 manager/vertexid.go mode change 100755 => 100644 model.go mode change 100755 => 100644 model/edge.go mode change 100755 => 100644 model/edge_test.go delete mode 100755 model/edgeid.go mode change 100755 => 100644 model/edgevalue.go mode change 100755 => 100644 model/idlist.go mode change 100755 => 100644 model/unmarshal.go mode change 100755 => 100644 model/vertex.go mode change 100755 => 100644 model/vertex_query.go mode change 100755 => 100644 model/vertex_test.go delete mode 100755 model/vertexid.go mode change 100755 => 100644 model/vertexproperty.go mode change 100755 => 100644 query/cardinality/cardinality.go mode change 100755 => 100644 query/graph/makepropertykey_test.go mode change 100755 => 100644 query/traversal/addproperty_test.go mode change 100755 => 100644 query/traversal/to.go mode change 100755 => 100644 quick/dropvertex.go mode change 100755 => 100644 quick/misc.go mode change 100755 => 100644 quick/schema.go mode change 100755 => 100644 quick/vertexid.go diff --git a/examples/vertex-edge-example/main.go b/examples/vertex-edge-example/main.go old mode 100755 new mode 100644 index 8640a76..88a267a --- a/examples/vertex-edge-example/main.go +++ b/examples/vertex-edge-example/main.go @@ -114,21 +114,24 @@ func printEdges(client *grammes.Client, edges []grammes.Edge) { } // Print the information about the edge including // its ID, label, and its properties. + logger.Info("Edge", zap.Any("ID", edges[0].ID()), zap.String("Label", edges[0].Label()), zap.Any("ageDiff", edges[0].PropertyValue("ageDiff")), zap.Any("driveDist", edges[0].PropertyValue("driveDist")), ) + logger.Info("OutVertex", zap.Any("ID", edges[0].OutVertexID()), zap.String("Label", edges[0].OutVertexLabel()), zap.Any("Name", v1.PropertyValue("name", 0)), ) + logger.Info("InVertex", zap.Any("ID", edges[0].InVertexID()), zap.String("Label", edges[0].InVertexLabel()), zap.Any("Name", v2.PropertyValue("name", 0)), ) } -} +} \ No newline at end of file diff --git a/gremconnect/response.go b/gremconnect/response.go old mode 100755 new mode 100644 index 47e4878..6122694 --- a/gremconnect/response.go +++ b/gremconnect/response.go @@ -53,8 +53,9 @@ func MarshalResponse(msg []byte) (Response, error) { code = status["code"].(float64) resp = Response{Code: int(code)} ) + message, _ := status["message"].(string) - err = responseDetectError(resp.Code) + err = responseDetectError(resp.Code, message) if err != nil { resp.Data = err // Use the Data field as a vehicle for the error. } else { @@ -67,7 +68,7 @@ func MarshalResponse(msg []byte) (Response, error) { // responseDetectError detects any possible errors in responses // from Gremlin Server and generates an error for each code -func responseDetectError(code int) error { +func responseDetectError(code int, message string) error { switch code { case 200: break @@ -76,25 +77,25 @@ func responseDetectError(code int) error { case 206: break case 401: - return gremerror.NewNetworkError(401, "UNAUTHORIZED") + return gremerror.NewNetworkError(401, "UNAUTHORIZED", message) case 407: - return gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED") + return gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED", message) case 498: - return gremerror.NewNetworkError(498, "MALFORMED REQUEST") + return gremerror.NewNetworkError(498, "MALFORMED REQUEST", message) case 499: - return gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS") + return gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS", message) case 500: - return gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR") + return gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR", message) case 503: - return gremerror.NewNetworkError(503, "SERVER UNAVAILABLE") + return gremerror.NewNetworkError(503, "SERVER UNAVAILABLE", message) case 597: - return gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR") + return gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR", message) case 598: - return gremerror.NewNetworkError(598, "SERVER TIMEOUT") + return gremerror.NewNetworkError(598, "SERVER TIMEOUT", message) case 599: - return gremerror.NewNetworkError(599, "SERIALIZATION ERROR") + return gremerror.NewNetworkError(599, "SERIALIZATION ERROR", message) default: - return gremerror.NewNetworkError(code, "UNKNOWN ERROR") + return gremerror.NewNetworkError(code, "UNKNOWN ERROR", message) } return nil } diff --git a/gremconnect/response_test.go b/gremconnect/response_test.go old mode 100755 new mode 100644 index 7238d08..8ee1d45 --- a/gremconnect/response_test.go +++ b/gremconnect/response_test.go @@ -77,6 +77,7 @@ var ( { "requestId": "d2476e5b-b2bc-6a70-2647-3991f68ab415", "status": { + "message": "Some error", "code": 401, "attributes": {} }, @@ -233,7 +234,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp401.Data should be 'UNAUTHORIZED'", func() { - So(resp401.Data, ShouldResemble, gremerror.NewNetworkError(401, "UNAUTHORIZED")) + So(resp401.Data, ShouldResemble, gremerror.NewNetworkError(401, "UNAUTHORIZED", "Some error")) }) Convey("Then the status code should be 407", func() { @@ -241,7 +242,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp407.Data should be 'AUTHENTICATE'", func() { - So(resp407.Data, ShouldResemble, gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED")) + So(resp407.Data, ShouldResemble, gremerror.NewNetworkError(407, "AUTHENTICATION REQUIRED", "")) }) Convey("Then the status code should be 498", func() { @@ -249,7 +250,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp498.Data should be 'MALFORMED REQUEST", func() { - So(resp498.Data, ShouldResemble, gremerror.NewNetworkError(498, "MALFORMED REQUEST")) + So(resp498.Data, ShouldResemble, gremerror.NewNetworkError(498, "MALFORMED REQUEST", "")) }) Convey("Then the status code should be 499", func() { @@ -257,7 +258,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp499.Data should be 'INVALID REQUEST ARGUMENTS'", func() { - So(resp499.Data, ShouldResemble, gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS")) + So(resp499.Data, ShouldResemble, gremerror.NewNetworkError(499, "INVALID REQUEST ARGUMENTS", "")) }) Convey("Then the status code should be 500", func() { @@ -265,7 +266,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp500.Data should be 'SERVER ERROR'", func() { - So(resp500.Data, ShouldResemble, gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR")) + So(resp500.Data, ShouldResemble, gremerror.NewNetworkError(500, "INTERNAL SERVER ERROR", "")) }) Convey("Then the status code should be 597", func() { @@ -273,7 +274,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp597.Data should be 'SCRIPT EVALUATION ERROR'", func() { - So(resp597.Data, ShouldResemble, gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR")) + So(resp597.Data, ShouldResemble, gremerror.NewNetworkError(597, "SCRIPT EVALUATION ERROR", "")) }) Convey("Then the status code should be 598", func() { @@ -281,7 +282,7 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp598.Data should be 'SERVER TIMEOUT'", func() { - So(resp598.Data, ShouldResemble, gremerror.NewNetworkError(598, "SERVER TIMEOUT")) + So(resp598.Data, ShouldResemble, gremerror.NewNetworkError(598, "SERVER TIMEOUT", "")) }) Convey("Then the status code should be 599", func() { @@ -289,11 +290,11 @@ func TestMarshalRespone(t *testing.T) { }) Convey("And resp599.Data should be 'SERVER SERIALIZATION ERROR'", func() { - So(resp599.Data, ShouldResemble, gremerror.NewNetworkError(599, "SERIALIZATION ERROR")) + So(resp599.Data, ShouldResemble, gremerror.NewNetworkError(599, "SERIALIZATION ERROR", "")) }) Convey("Then respDefault.Data should be 'UNKNOWN ERROR'", func() { - So(respDefault.Data, ShouldResemble, gremerror.NewNetworkError(403, "UNKNOWN ERROR")) + So(respDefault.Data, ShouldResemble, gremerror.NewNetworkError(403, "UNKNOWN ERROR", "")) }) }) }) diff --git a/gremerror/networkerror.go b/gremerror/networkerror.go old mode 100755 new mode 100644 index 8fc9d03..070dab5 --- a/gremerror/networkerror.go +++ b/gremerror/networkerror.go @@ -26,13 +26,15 @@ import "strconv" type NetworkError struct { statusCode int msg string + origMsg string } // NewNetworkError returns a status code related error. -func NewNetworkError(statusCode int, msg string) error { +func NewNetworkError(statusCode int, msg string, origMsg string) error { return &NetworkError{ statusCode: statusCode, msg: msg, + origMsg: origMsg, } } @@ -41,5 +43,6 @@ func (g *NetworkError) Error() string { fmtError("type", "NETWORK_ERROR"), fmtError("status code", strconv.Itoa(g.statusCode)), fmtError("error", g.msg), + fmtError("original error", g.origMsg), ) } diff --git a/manager/addvertex_test.go b/manager/addvertex_test.go old mode 100755 new mode 100644 index 7f81639..4f84510 --- a/manager/addvertex_test.go +++ b/manager/addvertex_test.go @@ -34,20 +34,15 @@ import ( var testVertex = model.Vertex{ Type: "testType", Value: model.VertexValue{ - ID: model.ID{ - Type: "testID", - Value: 1234, - }, + ID: 1234, Label: "testLabel", Properties: model.PropertyMap{"testDetail": []model.Property{ - model.Property{ + { Type: "testType", Value: model.PropertyValue{ ID: model.PropertyID{ - Type: "testIDType", - Value: model.PropertyIDValue{ - RelationID: "testRelID", - }, + Type: "testIDType", + Value: "testRelID", }, Value: model.ValueWrapper{ PropertyDetailedValue: model.PropertyDetailedValue{ @@ -76,7 +71,7 @@ func TestAddAPIVertex(t *testing.T) { data.Properties = map[string]string{"testkey": "testval"} v, _ := qm.AddAPIVertex(data) Convey("Then the return vertex ID value should be 28720", func() { - So(v.Value.ID.Value, ShouldEqual, 28720) + So(v.Value.ID, ShouldEqual, 28720) }) }) }) @@ -103,7 +98,7 @@ func TestAddVertexByStruct(t *testing.T) { Convey("When AddVertexByStruct is called", func() { res, _ := qm.AddVertexByStruct(testVertex) Convey("Then the return vertex ID value should be 28720", func() { - So(res.Value.ID.Value, ShouldEqual, 28720) + So(res.Value.ID, ShouldEqual, 28720) }) }) }) @@ -169,7 +164,7 @@ func TestAddVertexByQuery(t *testing.T) { var q mockQuery res, _ := qm.AddVertexByQuery(q) Convey("Then the return vertex ID value should be 28720", func() { - So(res.Value.ID.Value, ShouldEqual, 28720) + So(res.Value.ID, ShouldEqual, 28720) }) }) }) diff --git a/manager/dropvertex.go b/manager/dropvertex.go old mode 100755 new mode 100644 index 379e4b3..b40dddc --- a/manager/dropvertex.go +++ b/manager/dropvertex.go @@ -23,10 +23,10 @@ package manager import ( "strings" + "github.com/northwesternmutual/grammes/query/traversal" "github.com/northwesternmutual/grammes/gremerror" "github.com/northwesternmutual/grammes/logging" "github.com/northwesternmutual/grammes/query" - "github.com/northwesternmutual/grammes/query/traversal" ) type dropQueryManager struct { @@ -53,7 +53,7 @@ func (v *dropQueryManager) DropVertexLabel(label string) error { return nil } -func (v *dropQueryManager) DropVertexByID(ids ...int64) error { +func (v *dropQueryManager) DropVertexByID(ids ...interface{}) error { var err error for _, id := range ids { query := traversal.NewTraversal().V().HasID(id).Drop() @@ -72,7 +72,7 @@ func (v *dropQueryManager) DropVerticesByString(q string) error { if !strings.HasSuffix(q, "drop()") { q += ".drop()" } - + _, err := v.executeStringQuery(q) if err != nil { v.logger.Error("invalid query", @@ -90,4 +90,4 @@ func (v *dropQueryManager) DropVerticesByQuery(q query.Query) error { ) } return err -} +} \ No newline at end of file diff --git a/manager/getvertex.go b/manager/getvertex.go old mode 100755 new mode 100644 index c4efedf..bf5cafd --- a/manager/getvertex.go +++ b/manager/getvertex.go @@ -21,6 +21,7 @@ package manager import ( + "fmt" "strconv" "github.com/northwesternmutual/grammes/gremerror" @@ -104,9 +105,9 @@ func (c *getVertexQueryManager) AllVertices() ([]model.Vertex, error) { // ID assigned to it. This ID is unique to every // vertex on the graph. This is the best way of finding // vertices without any conflicting labels or properties. -func (c *getVertexQueryManager) VertexByID(id int64) (model.Vertex, error) { +func (c *getVertexQueryManager) VertexByID(id interface{}) (model.Vertex, error) { // Query the graph for a vertex with this ID. - vertices, err := c.VerticesByString("g.V().hasId(" + strconv.Itoa(int(id)) + ")") + vertices, err := c.VerticesByString("g.V().hasId(" + fmt.Sprint(id) + ")") if err != nil { c.logger.Error("error gathering vertices", gremerror.NewGrammesError("VerticesByID", err), diff --git a/manager/misc.go b/manager/misc.go old mode 100755 new mode 100644 index c51c988..5f6eea6 --- a/manager/misc.go +++ b/manager/misc.go @@ -21,6 +21,8 @@ package manager import ( + "errors" + "fmt" "strconv" "github.com/northwesternmutual/grammes/gremerror" @@ -46,7 +48,7 @@ func (m *miscQueryManager) DropAll() error { return err } -func (m *miscQueryManager) SetVertexProperty(id int64, keyAndVals ...interface{}) error { +func (m *miscQueryManager) SetVertexProperty(id interface{}, keyAndVals ...interface{}) error { if len(keyAndVals)%2 != 0 { m.logger.Error("number of parameters ["+strconv.Itoa(len(keyAndVals))+"]", gremerror.NewGrammesError("SetVertexProperty", gremerror.ErrOddNumberOfParameters), @@ -83,25 +85,31 @@ func (m *miscQueryManager) VertexCount() (int64, error) { return 0, err } - var resultingIDs model.IDList - - for _, res := range responses { - var rawIDs model.IDList + if len(responses) == 0 { + return 0, gremerror.ErrEmptyResponse + } - err = jsonUnmarshal(res, &rawIDs) - if err != nil { - m.logger.Error("id unmarshal", - gremerror.NewUnmarshalError("VertexCount", res, err), - ) - return 0, err - } + var rawResp model.IDList - resultingIDs.IDs = append(resultingIDs.IDs, rawIDs.IDs...) + err = jsonUnmarshal(responses[0], &rawResp) + if err != nil { + m.logger.Error("unmarshal", + gremerror.NewUnmarshalError("VertexCount", responses[0], err), + ) + return 0, err } - if len(resultingIDs.IDs) == 0 { - return 0, gremerror.ErrEmptyResponse + if len(rawResp.IDs) == 0 { + return 0, errors.New(fmt.Sprintf("invalid response %s", string(responses[0]))) + } + v, ok := rawResp.IDs[0].(map[string]interface{}) + if !ok { + return 0, errors.New(fmt.Sprintf("invalid response %s", string(responses[0]))) + } + count, ok := v["@value"].(float64) + if !ok { + return 0, errors.New(fmt.Sprintf("invalid response %s", string(responses[0]))) } - return resultingIDs.IDs[0].Value, nil + return int64(count), nil } diff --git a/manager/model.go b/manager/model.go old mode 100755 new mode 100644 index 658495d..1a5846e --- a/manager/model.go +++ b/manager/model.go @@ -42,15 +42,15 @@ var ( // unmarshalID will simply take a raw response and // unmarshal it into an ID. -func unmarshalID(data [][]byte) (id int64, err error) { +func unmarshalID(data [][]byte) (id interface{}, err error) { var resp model.VertexList for _, res := range data { var resPart model.VertexList err = jsonUnmarshal(res, &resPart) if err == nil { - if len(resp.Vertices) > 0 { - id = resp.Vertices[0].ID() + if len(resPart.Vertices) > 0 { + id = resPart.Vertices[0].ID() } } @@ -73,17 +73,17 @@ type MiscQuerier interface { // VertexCount will return the number of vertices on the graph. VertexCount() (count int64, err error) // SetVertexProperty will either add or set the property of a vertex. - SetVertexProperty(id int64, keyAndVals ...interface{}) error + SetVertexProperty(id interface{}, keyAndVals ...interface{}) error } // SchemaQuerier handles all schema related queries to the graph. type SchemaQuerier interface { // AddEdgeLabel adds a new edge label to the schema. - AddEdgeLabel(multi multiplicity.Multiplicity, label string) (id int64, err error) + AddEdgeLabel(multi multiplicity.Multiplicity, label string) (id interface{}, err error) // AddEdgeLabels adds new edge labels to the schema. - AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids []int64, err error) + AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids []interface{}, err error) // AddPropertyKey adds a new property key to the schema. - AddPropertyKey(label string, dt datatype.DataType, card cardinality.Cardinality) (id int64, err error) + AddPropertyKey(label string, dt datatype.DataType, card cardinality.Cardinality) (id interface{}, err error) // CommitSchema will finalize your changes and apply them to the schema. CommitSchema() (res [][]byte, err error) } @@ -93,7 +93,7 @@ type GetVertexQuerier interface { // AllVertices will return a slice of all vertices on the graph. AllVertices() (vertices []model.Vertex, err error) // VertexByID will return a single vertex based on the ID provided. - VertexByID(id int64) (vertex model.Vertex, err error) + VertexByID(id interface{}) (vertex model.Vertex, err error) // VerticesByString will return already unmarshalled vertex structs from a string query. VerticesByString(stringQuery string) (vertices []model.Vertex, err error) // VerticesByQuery will return already unmarshalled vertex structs from a query object. @@ -105,11 +105,11 @@ type GetVertexQuerier interface { // GetVertexIDQuerier holds functions to gather IDs from the graph. type GetVertexIDQuerier interface { // VertexIDsByString returns a slice of IDs from a string query. - VertexIDsByString(stringQuery string) (ids []int64, err error) + VertexIDsByString(stringQuery string) (ids []interface{}, err error) // VertexIDsByQuery returns a slice of IDs from a query object. - VertexIDsByQuery(queryObj query.Query) (ids []int64, err error) + VertexIDsByQuery(queryObj query.Query) (ids []interface{}, err error) // VertexIDs returns a slice of IDs based on the label and properties. - VertexIDs(label string, properties ...interface{}) (ids []int64, err error) + VertexIDs(label string, properties ...interface{}) (ids []interface{}, err error) } // AddVertexQuerier are queries specific to adding vertices. @@ -133,7 +133,7 @@ type DropQuerier interface { // DropVertexLabel drops all vertices with given label. DropVertexLabel(label string) error // DropVertexByID drops vertices based on their IDs. - DropVertexByID(ids ...int64) error + DropVertexByID(ids ...interface{}) error // DropVerticesByString drops vertices using a string query. DropVerticesByString(stringQuery string) error // DropVerticesByQuery drops vertices using a query object. diff --git a/manager/model_test.go b/manager/model_test.go old mode 100755 new mode 100644 index 648a676..528f82d --- a/manager/model_test.go +++ b/manager/model_test.go @@ -32,8 +32,8 @@ func TestUnmarshalID(t *testing.T) { Convey("Given a byte ID response", t, func() { Convey("When unmarshalID is called", func() { id, _ := unmarshalID([][]byte{[]byte(vertexResponse)}) - Convey("Then the return ID should be 0", func() { - So(id, ShouldEqual, 0) + Convey("Then the return ID should be 28720", func() { + So(id, ShouldEqual, 28720) }) }) }) diff --git a/manager/schema.go b/manager/schema.go old mode 100755 new mode 100644 index f5ca821..2877369 --- a/manager/schema.go +++ b/manager/schema.go @@ -46,7 +46,7 @@ func newSchemaManager(logger logging.Logger, executor stringExecutor) *schemaMan // AddEdgeLabel adds the edge label to the // graph directly. This method returns the schema id // of the edge label added. -func (s *schemaManager) AddEdgeLabel(multi multiplicity.Multiplicity, label string) (id int64, err error) { +func (s *schemaManager) AddEdgeLabel(multi multiplicity.Multiplicity, label string) (id interface{}, err error) { var ( data [][]byte query = graph.NewGraph().OpenManagement().MakeEdgeLabel(label).Multiplicity(multi).Make() @@ -78,7 +78,7 @@ func (s *schemaManager) AddEdgeLabel(multi multiplicity.Multiplicity, label stri // but with the ability to do multiple labels at a // time. This function is called similarly to your // favorite logger. -func (s *schemaManager) AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids []int64, err error) { +func (s *schemaManager) AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids []interface{}, err error) { if len(multiplicityAndLabels)%2 != 0 { s.logger.Error(fmt.Sprintf("number of parameters [%d]", len(multiplicityAndLabels)), gremerror.NewGrammesError("AddEdgeLabels", gremerror.ErrOddNumberOfParameters), @@ -89,7 +89,7 @@ func (s *schemaManager) AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids var ( multi multiplicity.Multiplicity label string - id int64 + id interface{} ok bool ) @@ -112,7 +112,7 @@ func (s *schemaManager) AddEdgeLabels(multiplicityAndLabels ...interface{}) (ids // AddPropertyKey adds the edge label to the // graph directly. This method returns the schema id // of the edge label added. -func (s *schemaManager) AddPropertyKey(propertyName string, datatype datatype.DataType, cardinality cardinality.Cardinality) (id int64, err error) { +func (s *schemaManager) AddPropertyKey(propertyName string, datatype datatype.DataType, cardinality cardinality.Cardinality) (id interface{}, err error) { var ( data [][]byte query = graph.NewGraph().OpenManagement().MakePropertyKey(propertyName, datatype, cardinality).Make() diff --git a/manager/vertexid.go b/manager/vertexid.go old mode 100755 new mode 100644 index 07baea9..09e77c0 --- a/manager/vertexid.go +++ b/manager/vertexid.go @@ -46,7 +46,7 @@ func newVertexIDQueryManager(logger logging.Logger, executor stringExecutor) *ve // VertexIDsByString executes a string query and unmarshals the // IDs for the user. -func (v *vertexIDQueryManager) VertexIDsByString(q string) ([]int64, error) { +func (v *vertexIDQueryManager) VertexIDsByString(q string) ([]interface{}, error) { if !strings.HasSuffix(q, ".id()") { q += ".id()" } @@ -75,10 +75,10 @@ func (v *vertexIDQueryManager) VertexIDsByString(q string) ([]int64, error) { rawIDs.IDs = append(rawIDs.IDs, idPart.IDs...) } - var ids []int64 + var ids []interface{} for _, id := range rawIDs.IDs { - ids = append(ids, id.Value) + ids = append(ids, id) } return ids, nil @@ -86,8 +86,8 @@ func (v *vertexIDQueryManager) VertexIDsByString(q string) ([]int64, error) { // VertexIDsByQuery will take a query and execute it. Then it will // run through and extract all the vertex IDs matching the -// traversal and return them in an array of int64. -func (v *vertexIDQueryManager) VertexIDsByQuery(query query.Query) ([]int64, error) { +// traversal and return them in an array. +func (v *vertexIDQueryManager) VertexIDsByQuery(query query.Query) ([]interface{}, error) { ids, err := v.VertexIDsByString(query.String()) if err != nil { v.logger.Error("error gathering IDs", @@ -100,7 +100,7 @@ func (v *vertexIDQueryManager) VertexIDsByQuery(query query.Query) ([]int64, err // VertexIDs takes the label and optional properties to retrieve // the IDs desired from the graph. -func (v *vertexIDQueryManager) VertexIDs(label string, properties ...interface{}) ([]int64, error) { +func (v *vertexIDQueryManager) VertexIDs(label string, properties ...interface{}) ([]interface{}, error) { if len(properties)%2 != 0 { v.logger.Error("number of parameters ["+strconv.Itoa(len(properties))+"]", gremerror.NewGrammesError("VertexIDs", gremerror.ErrOddNumberOfParameters), diff --git a/model.go b/model.go old mode 100755 new mode 100644 index c9889b2..a7d6d6d --- a/model.go +++ b/model.go @@ -38,9 +38,6 @@ var ( // UnmarshalEdgeList is a utility to unmarshal a list // or array of edges properly. UnmarshalEdgeList = model.UnmarshalEdgeList - // UnmarshalIDList is a utility to unmarshal a list - // or array of IDs properly. - UnmarshalIDList = model.UnmarshalIDList // UnmarshalVertexList is a utility to unmarshal a list // or array of vertices properly. UnmarshalVertexList = model.UnmarshalVertexList @@ -114,14 +111,6 @@ type PropertyMap = model.PropertyMap // value, and label of this property's value. type PropertyValue = model.PropertyValue -// ID is used to get quick access -// to the model.ID without having to -// import it everywhere in the grammes package. -// -// ID contains the data stores in the -// 'ID' data including the type and Value -type ID = model.ID - // APIData is used to get quick access // to the model.APIData without having to // import it everywhere in the grammes package. diff --git a/model/edge.go b/model/edge.go old mode 100755 new mode 100644 index 60a964b..b223e2d --- a/model/edge.go +++ b/model/edge.go @@ -43,8 +43,8 @@ func (e *Edge) PropertyValue(key string) interface{} { } // ID will retrieve the Edge ID for you. -func (e *Edge) ID() string { - return e.Value.ID.Value.RelationID +func (e *Edge) ID() interface{} { + return e.Value.ID } // Label will retrieve the Edge Label for you. @@ -54,14 +54,14 @@ func (e *Edge) Label() string { // OutVertexID will retrieve the id for the // vertex that the edge goes out of. -func (e *Edge) OutVertexID() (id int64) { - return e.Value.OutV.Value +func (e *Edge) OutVertexID() interface{} { + return e.Value.OutV } // InVertexID will retrieve the id for the // vertex that the edge goes into. -func (e *Edge) InVertexID() (id int64) { - return e.Value.InV.Value +func (e *Edge) InVertexID() interface{} { + return e.Value.InV } // OutVertexLabel will retrieve the label diff --git a/model/edge_test.go b/model/edge_test.go old mode 100755 new mode 100644 index d1f7b94..5e1e328 --- a/model/edge_test.go +++ b/model/edge_test.go @@ -41,9 +41,7 @@ func TestPropertyValue(t *testing.T) { func TestID(t *testing.T) { Convey("Given a variable that represents the Edge struct", t, func() { - // erid := EdgeRelationID{RelationID: "testRelID"} - // ev := EdgeValue{ID: EdgeID{Value: erid}} - e := Edge{Type: "tesType", Value: EdgeValue{ID: EdgeID{Value: EdgeRelationID{RelationID: "testRelID"}}}} + e := Edge{Type: "tesType", Value: EdgeValue{ID: "testRelID"}} Convey("When 'ID' is called", func() { result := e.ID() @@ -72,7 +70,7 @@ func TestOutVertexID(t *testing.T) { Convey("Given a variable that represents the Edge struct", t, func() { // erid := EdgeRelationID{RelationID: "testRelID"} // ev := EdgeValue{ID: EdgeID{Value: erid}} - e := Edge{Type: "tesType", Value: EdgeValue{OutV: EdgeVertex{Value: 12345}}} + e := Edge{Type: "tesType", Value: EdgeValue{OutV: 12345}} Convey("When 'OutVertexID' is called", func() { result := e.OutVertexID() @@ -85,7 +83,7 @@ func TestOutVertexID(t *testing.T) { func TestInVertexID(t *testing.T) { Convey("Given a variable that represents the Edge struct", t, func() { - e := Edge{Type: "tesType", Value: EdgeValue{InV: EdgeVertex{Value: 54321}}} + e := Edge{Type: "tesType", Value: EdgeValue{InV: 54321}} Convey("When 'InVertexID' is called", func() { result := e.InVertexID() @@ -126,7 +124,7 @@ func TestInVertexLabel(t *testing.T) { func TestQueryOutVertex(t *testing.T) { Convey("Given a variable that represents the Edge struct", t, func() { - e := Edge{Type: "tesType", Value: EdgeValue{OutV: EdgeVertex{Value: 12345}}} + e := Edge{Type: "tesType", Value: EdgeValue{OutV: 12345}} Convey("When 'QueryOutVertex' is called with a string", func() { var client queryClient @@ -141,7 +139,7 @@ func TestQueryOutVertex(t *testing.T) { func TestQueryInVertex(t *testing.T) { Convey("Given a variable that represents the Edge struct", t, func() { - e := Edge{Type: "tesType", Value: EdgeValue{OutV: EdgeVertex{Value: 12345}}} + e := Edge{Type: "tesType", Value: EdgeValue{OutV: 12345}} Convey("When 'QueryInVertex' is called with a string", func() { var client queryClient diff --git a/model/edgeid.go b/model/edgeid.go deleted file mode 100755 index 230f9a4..0000000 --- a/model/edgeid.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2018 Northwestern Mutual. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package model - -// EdgeID is the main wrapper struct -// that holds the type and ID itself. -type EdgeID struct { - Type string `json:"@type"` - Value EdgeRelationID `json:"@value"` -} - -// EdgeRelationID contains the ID of the -// edge and its relationship status between -// vertices. -type EdgeRelationID struct { - RelationID string `json:"relationId"` -} diff --git a/model/edgevalue.go b/model/edgevalue.go old mode 100755 new mode 100644 index ce0e1b0..f04cf41 --- a/model/edgevalue.go +++ b/model/edgevalue.go @@ -23,18 +23,11 @@ package model // EdgeValue contains the 'value' data // from the Edge object. type EdgeValue struct { - ID EdgeID `json:"id"` + ID interface{} `json:"id"` Label string `json:"label"` InVLabel string `json:"inVLabel,omitempty"` OutVLabel string `json:"outVLabel,omitempty"` - InV EdgeVertex `json:"inV,omitempty"` - OutV EdgeVertex `json:"outV,omitempty"` + InV interface{} `json:"inV,omitempty"` + OutV interface{} `json:"outV,omitempty"` Properties EdgeProperties `json:"properties,omitempty"` } - -// EdgeVertex only contains the type -// and ID of the vertex. -type EdgeVertex struct { - Type string `json:"@type"` - Value int64 `json:"@value"` -} diff --git a/model/idlist.go b/model/idlist.go old mode 100755 new mode 100644 index 0c10056..44fc45e --- a/model/idlist.go +++ b/model/idlist.go @@ -26,7 +26,7 @@ import "encoding/json" // We use this instead of []ID for Gremlin v3.0 compatibility. type IDList struct { listOfIDs List - IDs []ID + IDs []interface{} } // UnmarshalJSON overrides to assure a proper unmarshal. diff --git a/model/unmarshal.go b/model/unmarshal.go old mode 100755 new mode 100644 index 532b802..d250d14 --- a/model/unmarshal.go +++ b/model/unmarshal.go @@ -60,23 +60,6 @@ func UnmarshalEdgeList(data [][]byte) ([]Edge, error) { return list, nil } -// UnmarshalIDList is a utility to unmarshal a list -// or array of IDs properly. -func UnmarshalIDList(data [][]byte) ([]ID, error) { - var list []ID - - for _, res := range data { - var listPart IDList - if err := json.Unmarshal(res, &listPart); err != nil { - return nil, gremerror.NewUnmarshalError("UnmarshalIDList", res, err) - } - - list = append(list, listPart.IDs...) - } - - return list, nil -} - // UnmarshalPropertyList is a utility to unmarshal a list // or array of IDs properly. func UnmarshalPropertyList(data [][]byte) ([]Property, error) { diff --git a/model/vertex.go b/model/vertex.go old mode 100755 new mode 100644 index 60c9720..4ca2c69 --- a/model/vertex.go +++ b/model/vertex.go @@ -43,7 +43,6 @@ func NewVertex(label string, properties ...interface{}) Vertex { var v = Vertex{ Type: "g:Vertex", Value: VertexValue{ - ID: ID{}, Properties: make(PropertyMap), Label: label, }, @@ -77,8 +76,8 @@ func (v *Vertex) PropertyMap() PropertyMap { // ID will retrieve the Vertex ID for you // without having to traverse all the way through the structures. -func (v *Vertex) ID() int64 { - return v.Value.ID.Value +func (v *Vertex) ID() interface{} { + return v.Value.ID } // Label retrieves the label of the vertex diff --git a/model/vertex_query.go b/model/vertex_query.go old mode 100755 new mode 100644 index 2554f65..34da14e --- a/model/vertex_query.go +++ b/model/vertex_query.go @@ -134,7 +134,7 @@ func (v *Vertex) QueryInEdges(client queryClient, labels ...string) ([]Edge, err // AddEdge adds an outgoing edge from this Vertex object to // another Vertex object via its unique ID. -func (v *Vertex) AddEdge(client queryClient, label string, outVID int64, properties ...interface{}) (Edge, error) { +func (v *Vertex) AddEdge(client queryClient, label string, outVID interface{}, properties ...interface{}) (Edge, error) { if client == nil { return Edge{}, gremerror.NewGrammesError("AddEdge", gremerror.ErrNilClient) } diff --git a/model/vertex_test.go b/model/vertex_test.go old mode 100755 new mode 100644 index 4788cee..651b2b5 --- a/model/vertex_test.go +++ b/model/vertex_test.go @@ -28,11 +28,11 @@ import ( func TestVertexPropertyValue(t *testing.T) { Convey("Given a variable that represents the Vertex struct", t, func() { - testID := PropertyID{Value: PropertyIDValue{RelationID: "relID"}} + testID := PropertyID{Value: "relID"} testValue := ValueWrapper{PropertyDetailedValue: PropertyDetailedValue{Value: "tstInterface", Type: "pdvType"}} pi := Property{Type: "piType", Value: PropertyValue{ID: testID, Value: testValue, Label: "tstLabel"}} - pdmap := map[string][]Property{"testKey": []Property{pi}} + pdmap := map[string][]Property{"testKey": {pi}} v := Vertex{Type: "tesType", Value: VertexValue{Properties: pdmap}} @@ -47,12 +47,12 @@ func TestVertexPropertyValue(t *testing.T) { func TestVertexID(t *testing.T) { Convey("Given a variable that represents the Vertex struct", t, func() { - testID := PropertyID{Value: PropertyIDValue{RelationID: "relID"}} + testID := PropertyID{Value: "relID"} testValue := ValueWrapper{PropertyDetailedValue: PropertyDetailedValue{Value: "tstInterface", Type: "pdvType"}} pi := Property{Type: "piType", Value: PropertyValue{ID: testID, Value: testValue, Label: "tstLabel"}} - pdmap := map[string][]Property{"testKey": []Property{pi}} + pdmap := map[string][]Property{"testKey": {pi}} - v := Vertex{Type: "tesType", Value: VertexValue{Properties: pdmap, ID: ID{Value: 6789}}} + v := Vertex{Type: "tesType", Value: VertexValue{Properties: pdmap, ID: 6789}} Convey("When 'ID' is called with a string and int", func() { result := v.ID() @@ -65,12 +65,12 @@ func TestVertexID(t *testing.T) { func TestVertexLabel(t *testing.T) { Convey("Given a variable that represents the Vertex struct", t, func() { - testID := PropertyID{Value: PropertyIDValue{RelationID: "relID"}} + testID := PropertyID{Value: "relID"} testValue := ValueWrapper{PropertyDetailedValue: PropertyDetailedValue{Value: "tstInterface", Type: "pdvType"}} pi := Property{Type: "piType", Value: PropertyValue{ID: testID, Value: testValue, Label: "tstLabel"}} - pdmap := map[string][]Property{"testKey": []Property{pi}} + pdmap := map[string][]Property{"testKey": {pi}} - v := Vertex{Type: "tesType", Value: VertexValue{Label: "testLabel", ID: ID{Value: 6789}, Properties: pdmap}} + v := Vertex{Type: "tesType", Value: VertexValue{Label: "testLabel", ID: 6789, Properties: pdmap}} Convey("When 'Label' is called with a string and int", func() { result := v.Label() diff --git a/model/vertexid.go b/model/vertexid.go deleted file mode 100755 index 514c412..0000000 --- a/model/vertexid.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2018 Northwestern Mutual. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package model - -// ID contains the data stores in the -// 'ID' data including the type and Value -type ID struct { - Type string `json:"@type"` - Value int64 `json:"@value"` -} diff --git a/model/vertexproperty.go b/model/vertexproperty.go old mode 100755 new mode 100644 index e6bbd5a..7e5ae0f --- a/model/vertexproperty.go +++ b/model/vertexproperty.go @@ -80,12 +80,6 @@ type PropertyValue struct { // PropertyID holds the ID that is used // for the property itself. type PropertyID struct { - Type string `json:"@type"` - Value PropertyIDValue `json:"@value"` -} - -// PropertyIDValue holds the value -// of the PropertyID. -type PropertyIDValue struct { - RelationID string `json:"relationId"` + Type string `json:"@type"` + Value interface{} `json:"@value"` } diff --git a/query/cardinality/cardinality.go b/query/cardinality/cardinality.go old mode 100755 new mode 100644 index a57e293..1a20e20 --- a/query/cardinality/cardinality.go +++ b/query/cardinality/cardinality.go @@ -46,13 +46,13 @@ type Cardinality string const ( // List allows an arbitrary number of // values per element for such key. - List Cardinality = "LIST" + List Cardinality = "list" // Set allows multiple values but no // duplicate values per element for such key. - Set Cardinality = "SET" + Set Cardinality = "set" // Single allows at most one // value per element for such key - Single Cardinality = "SINGLE" + Single Cardinality = "single" ) // String will convert Cardinality to a string diff --git a/query/graph/makepropertykey_test.go b/query/graph/makepropertykey_test.go old mode 100755 new mode 100644 index 94d74cf..2cc6626 --- a/query/graph/makepropertykey_test.go +++ b/query/graph/makepropertykey_test.go @@ -34,13 +34,11 @@ func TestMakePropertyKey(t *testing.T) { g := NewGraph() Convey("When 'MakePropertyKey' is called with a label string, DataType and Cardinality", func() { - var dt datatype.DataType - dt = "String.class" - var cr cardinality.Cardinality - cr = "LIST" + var dt = datatype.String + var cr = cardinality.List result := g.MakePropertyKey("labelTest", dt, cr) - Convey("Then result should equal 'graph.makePropertyKey('labelTest').dataType(String.class).cardinality(LIST)'", func() { - So(result.String(), ShouldEqual, "graph.makePropertyKey(\"labelTest\").dataType(String.class).cardinality(LIST)") + Convey("Then result should equal 'graph.makePropertyKey('labelTest').dataType(String.class).cardinality(list)'", func() { + So(result.String(), ShouldEqual, "graph.makePropertyKey(\"labelTest\").dataType(String.class).cardinality(list)") }) }) }) diff --git a/query/traversal/addproperty_test.go b/query/traversal/addproperty_test.go old mode 100755 new mode 100644 index f170f26..8528010 --- a/query/traversal/addproperty_test.go +++ b/query/traversal/addproperty_test.go @@ -38,8 +38,8 @@ func TestProperty(t *testing.T) { }) Convey("When 'Property' is called with object strings and cardinality", func() { result := g.Property(cardinality.Set, "obj1", "obj2") - Convey("Then result should equal 'g.property(SET,'obj1','obj2')'", func() { - So(result.String(), ShouldEqual, "g.property(SET,\"obj1\",\"obj2\")") + Convey("Then result should equal 'g.property(set,'obj1','obj2')'", func() { + So(result.String(), ShouldEqual, "g.property(set,\"obj1\",\"obj2\")") }) }) Convey("When 'Property' is called with object strings and ints", func() { diff --git a/query/traversal/pagerank_test.go b/query/traversal/pagerank_test.go index e4d48b3..bda9298 100644 --- a/query/traversal/pagerank_test.go +++ b/query/traversal/pagerank_test.go @@ -38,8 +38,8 @@ func TestPageRank(t *testing.T) { Convey("When 'PageRank' is called with one argument", func() { result := g.PageRank(1.234) - Convey("Then result should equal 'g.pageRank(1.234)'", func() { - So(result.String(), ShouldEqual, "g.pageRank(1.234)") + Convey("Then result should equal 'g.pageRank(1.234000d)'", func() { + So(result.String(), ShouldEqual, "g.pageRank(1.234000d)") }) }) diff --git a/query/traversal/skip_test.go b/query/traversal/skip_test.go index c69135a..b472e9b 100644 --- a/query/traversal/skip_test.go +++ b/query/traversal/skip_test.go @@ -39,8 +39,8 @@ func TestSkip(t *testing.T) { Convey("When 'Skip' is called with multiple extraFloat arguments", func() { result := g.Skip(scope.Local, 1.234) - Convey("Then result should equal 'g.skip(local,1.234)'", func() { - So(result.String(), ShouldEqual, "g.skip(local,1.234)") + Convey("Then result should equal 'g.skip(local,1.234000d)'", func() { + So(result.String(), ShouldEqual, "g.skip(local,1.234000d)") }) }) }) diff --git a/query/traversal/timeLimit_test.go b/query/traversal/timeLimit_test.go index f3efd73..9f86217 100644 --- a/query/traversal/timeLimit_test.go +++ b/query/traversal/timeLimit_test.go @@ -31,8 +31,8 @@ func TestTimeLimit(t *testing.T) { g := NewTraversal() Convey("When 'Store' is called", func() { result := g.TimeLimit(1.234) - Convey("Then result should equal 'g.timeLimit(1.234)'", func() { - So(result.String(), ShouldEqual, "g.timeLimit(1.234)") + Convey("Then result should equal 'g.timeLimit(1.234000d)'", func() { + So(result.String(), ShouldEqual, "g.timeLimit(1.234000d)") }) }) }) diff --git a/query/traversal/to.go b/query/traversal/to.go old mode 100755 new mode 100644 index d03144d..24db25b --- a/query/traversal/to.go +++ b/query/traversal/to.go @@ -83,7 +83,7 @@ func (g String) ToV(dir direction.Direction) String { // ToVId can be used to make a string query that will take a vertex id as a parameter, // and can be used to point an edge towards this vertex ID. -func (g String) ToVId(vertexID int64) String { +func (g String) ToVId(vertexID interface{}) String { g = g.append(fmtStr(".to(V().hasId(%v))", vertexID)) return g diff --git a/query/traversal/util_test.go b/query/traversal/util_test.go index de9bc6c..ceb5c11 100644 --- a/query/traversal/util_test.go +++ b/query/traversal/util_test.go @@ -56,8 +56,8 @@ func TestAddStep(t *testing.T) { Convey("When AddStep is called with int64", func() { i := int64(1234) g.AddStep("test", i) - Convey("Then g should equal g.test(1234)", func() { - So(g.String(), ShouldEqual, "g.test(1234)") + Convey("Then g should equal g.test(1234L)", func() { + So(g.String(), ShouldEqual, "g.test(1234L)") }) }) @@ -65,7 +65,7 @@ func TestAddStep(t *testing.T) { i := float64(1.234) g.AddStep("test", i) Convey("Then g should equal g.test(1.234)", func() { - So(g.String(), ShouldEqual, "g.test(1.234)") + So(g.String(), ShouldEqual, "g.test(1.234000d)") }) }) diff --git a/query/traversal/withsack_test.go b/query/traversal/withsack_test.go index 1e9360e..149856b 100644 --- a/query/traversal/withsack_test.go +++ b/query/traversal/withsack_test.go @@ -31,8 +31,8 @@ func TestWithSack(t *testing.T) { g := NewTraversal() Convey("When WithSack is called with float", func() { result := g.WithSack(1.234) - Convey("Then result should equal g.withSack(1.234)", func() { - So(result.String(), ShouldEqual, "g.withSack(1.234)") + Convey("Then result should equal g.withSack(1.234000d)", func() { + So(result.String(), ShouldEqual, "g.withSack(1.234000d)") }) }) }) diff --git a/quick/dropvertex.go b/quick/dropvertex.go old mode 100755 new mode 100644 index bcdf600..0b064cd --- a/quick/dropvertex.go +++ b/quick/dropvertex.go @@ -43,7 +43,7 @@ func DropVertexLabel(host, label string) error { // DropVertexByID will search for vertices with the // provided IDs and drop them if such vertices exist. -func DropVertexByID(host string, ids ...int64) error { +func DropVertexByID(host string, ids ...interface{}) error { err := checkForClient(host) if err != nil { return err diff --git a/quick/misc.go b/quick/misc.go old mode 100755 new mode 100644 index c0f7385..1116a70 --- a/quick/misc.go +++ b/quick/misc.go @@ -38,7 +38,7 @@ func DropAll(host string) error { // SetVertexProperty will search the graph for a vertex // with the given ID and set the properties provided. -func SetVertexProperty(host string, id int64, properties ...interface{}) error { +func SetVertexProperty(host string, id interface{}, properties ...interface{}) error { err := checkForClient(host) if err != nil { return err diff --git a/quick/schema.go b/quick/schema.go old mode 100755 new mode 100644 index 93e94f2..80353b0 --- a/quick/schema.go +++ b/quick/schema.go @@ -29,7 +29,7 @@ import ( // AddEdgeLabel adds the edge label to the // graph directly. This method returns the schema id // of the edge label added. -func AddEdgeLabel(multi multiplicity.Multiplicity, host, label string) (int64, error) { +func AddEdgeLabel(multi multiplicity.Multiplicity, host, label string) (interface{}, error) { err := checkForClient(host) if err != nil { return 0, err @@ -48,7 +48,7 @@ func AddEdgeLabel(multi multiplicity.Multiplicity, host, label string) (int64, e // but with the ability to do multiple labels at a // time. This function is called similarly to your // favorite logger. -func AddEdgeLabels(host string, multiplicityAndLabels ...interface{}) ([]int64, error) { +func AddEdgeLabels(host string, multiplicityAndLabels ...interface{}) ([]interface{}, error) { err := checkForClient(host) if err != nil { return nil, err @@ -66,7 +66,7 @@ func AddEdgeLabels(host string, multiplicityAndLabels ...interface{}) ([]int64, // AddPropertyKey adds the edge label to the // graph directly. This method returns the schema id // of the edge label added. -func AddPropertyKey(host, propertyName string, datatype datatype.DataType, cardinality cardinality.Cardinality) (int64, error) { +func AddPropertyKey(host, propertyName string, datatype datatype.DataType, cardinality cardinality.Cardinality) (interface{}, error) { err := checkForClient(host) if err != nil { return 0, err diff --git a/quick/vertexid.go b/quick/vertexid.go old mode 100755 new mode 100644 index edee983..7c22fb2 --- a/quick/vertexid.go +++ b/quick/vertexid.go @@ -24,8 +24,8 @@ import "github.com/northwesternmutual/grammes/query" // VertexIDsByQuery will take a query and execute it. Then it will // run through and extract all the vertex IDs matching the -// traversal and return them in an array of int64. -func VertexIDsByQuery(host string, q query.Query) ([]int64, error) { +// traversal and return them in an array. +func VertexIDsByQuery(host string, q query.Query) ([]interface{}, error) { err := checkForClient(host) if err != nil { return nil, err @@ -42,7 +42,7 @@ func VertexIDsByQuery(host string, q query.Query) ([]int64, error) { // VertexIDs takes the label and optional properties to retrieve // the IDs desired from the graph. -func VertexIDs(host, label string, properties ...interface{}) ([]int64, error) { +func VertexIDs(host, label string, properties ...interface{}) ([]interface{}, error) { err := checkForClient(host) if err != nil { return nil, err From cab68bbe1d0da88c4afbee5eaede1263304a85cd Mon Sep 17 00:00:00 2001 From: Zubair Nabi Date: Fri, 13 Jan 2023 13:26:54 +0500 Subject: [PATCH 10/16] Adding test for addEdges. --- model/vertex_query.go | 30 ++++++++++++++++++++++-------- model/vertex_test.go | 28 +++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/model/vertex_query.go b/model/vertex_query.go index 34da14e..f332671 100644 --- a/model/vertex_query.go +++ b/model/vertex_query.go @@ -215,25 +215,25 @@ func (v *Vertex) AddProperty(client queryClient, key string, value interface{}) type EdgeWithPropsAndLabel struct { Label string - Id int64 + Id interface{} Properties []interface{} } -func (v *Vertex) AddEdges(client queryClient, edges []EdgeWithPropsAndLabel) error { +func (v *Vertex) AddEdges(client queryClient, inputEdges []EdgeWithPropsAndLabel) ([]Edge, error) { if client == nil { - return gremerror.NewGrammesError("AddEdges", gremerror.ErrNilClient) + return []Edge{}, gremerror.NewGrammesError("AddEdges", gremerror.ErrNilClient) } var query = newTrav().V().HasID(v.ID()) - for i, edge := range edges { + for i, edge := range inputEdges { if i != 0 { query = query.OutV() } query = query.AddE(edge.Label).To(newTrav().V().HasID(edge.Id).Raw()) if len(edge.Properties)%2 != 0 { - return gremerror.NewGrammesError("AddEdges", gremerror.ErrOddNumberOfParameters) + return []Edge{}, gremerror.NewGrammesError("AddEdges", gremerror.ErrOddNumberOfParameters) } if len(edge.Properties) > 0 { @@ -243,9 +243,23 @@ func (v *Vertex) AddEdges(client queryClient, edges []EdgeWithPropsAndLabel) err } } - _, err := client.ExecuteQuery(query) + // Execute the built command. + responses, err := client.ExecuteQuery(query) if err != nil { - return gremerror.NewQueryError("AddEdges", query.String(), err) + return []Edge{}, gremerror.NewQueryError("AddEdges", query.String(), err) } - return nil + + var edges EdgeList + edgeList, err := UnmarshalEdgeList(responses) + if err != nil { + return []Edge{}, err + } + + edges.Edges = edgeList + + if len(edges.Edges) == 0 { + return []Edge{}, gremerror.NewGrammesError("AddEdges", gremerror.ErrEmptyResponse) + } + + return edges.Edges, nil } diff --git a/model/vertex_test.go b/model/vertex_test.go index 651b2b5..82b7037 100644 --- a/model/vertex_test.go +++ b/model/vertex_test.go @@ -130,7 +130,7 @@ func TestAddEdge(t *testing.T) { Convey("Given a variable that represents the Vertex struct", t, func() { v := Vertex{Type: "tesType"} - Convey("When 'AddEdges' is called with a string and int", func() { + Convey("When 'AddEdge' is called with a string and int", func() { var client queryClient var edge Edge var tstoutVID int64 @@ -143,3 +143,29 @@ func TestAddEdge(t *testing.T) { }) }) } + +func TestAddEdges(t *testing.T) { + Convey("Given a variable that represents the Vertex struct", t, func() { + + v := Vertex{Type: "tesType"} + Convey("When 'AddEdges' is called with two edges", func() { + var client queryClient + var tstoutVID int64 + tstoutVID = 12345 + edge1 := EdgeWithPropsAndLabel{ + Label: "testLbl", + Id: tstoutVID, + Properties: []interface{}{"tstIntrf1", 7777, "tstIntrf2", 9876}, + } + edge2 := EdgeWithPropsAndLabel{ + Label: "testLb2", + Id: tstoutVID, + Properties: []interface{}{"tstIntrf1", 8888, "tstIntrf2", 5432}, + } + result, _ := v.AddEdges(client, []EdgeWithPropsAndLabel{edge1, edge2}) + Convey("Then result should equal two edges", func() { + So(result, ShouldResemble, []Edge{}) + }) + }) + }) +} From 9031cc2b6964110a1fa1503d84170d35da5ee7ea Mon Sep 17 00:00:00 2001 From: Zubair Nabi Date: Fri, 13 Jan 2023 13:45:09 +0500 Subject: [PATCH 11/16] Adding tests for SetList and SetProperty. --- query/traversal/util_test.go | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/query/traversal/util_test.go b/query/traversal/util_test.go index ceb5c11..b993d4e 100644 --- a/query/traversal/util_test.go +++ b/query/traversal/util_test.go @@ -126,3 +126,44 @@ func TestGatherInts(t *testing.T) { }) }) } + +func TestAddListProperty(t *testing.T) { + Convey("Given a graph traversal", t, func() { + g := NewTraversal() + Convey("When AddListProperty is called with a key and zero properties", func() { + g.AddListProperty("key1", []string{}) + Convey("Then g should equal g", func() { + So(g.String(), ShouldEqual, "g") + }) + }) + + Convey("When AddListProperty is called with a key and 2 properties", func() { + g.AddListProperty("key1", []string{"value1", "value2"}) + Convey("Then g should equal g.property(list, \"key1\", \"value1\").property(list, \"key1\", \"value2\")", func() { + So(g.String(), ShouldEqual, "g.property(list, \"key1\", \"value1\").property(list, \"key1\", \"value2\")") + }) + }) + }) +} + +func TestAddSetProperty(t *testing.T) { + Convey("Given a graph traversal", t, func() { + g := NewTraversal() + Convey("When AddSetProperty is called with a key and zero properties", func() { + var zeroProps []interface{} + g.AddSetProperty("key1", zeroProps) + Convey("Then g should equal g", func() { + So(g.String(), ShouldEqual, "g") + }) + }) + + Convey("When AddSetProperty is called with a key and 6 properties of different types", func() { + var props []interface{} + props = append(props, "value1", 3.4e+38, 1.7e+308, 9223372036854775807, 1, true) + g.AddSetProperty("key1", props) + Convey("Then g should equal g.property(set, \"key1\", \"value1\").property(set, \"key1\", 339999999999999996123846586046231871488.000000d).property(set, \"key1\", 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000d).property(set, \"key1\", 9223372036854775807).property(set, \"key1\", 1).property(set, \"key1\", true)", func() { + So(g.String(), ShouldEqual, "g.property(set, \"key1\", \"value1\").property(set, \"key1\", 339999999999999996123846586046231871488.000000d).property(set, \"key1\", 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000d).property(set, \"key1\", 9223372036854775807).property(set, \"key1\", 1).property(set, \"key1\", true)") + }) + }) + }) +} From f792e4382f6fe784924da084d38358d12cf792fd Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Sun, 22 Jan 2023 19:17:51 +0500 Subject: [PATCH 12/16] removing some changes --- query/traversal/addproperty.go | 45 +++------------------------------- query/traversal/graph.go | 12 ++------- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/query/traversal/addproperty.go b/query/traversal/addproperty.go index c87afd2..feba93d 100755 --- a/query/traversal/addproperty.go +++ b/query/traversal/addproperty.go @@ -20,12 +20,6 @@ package traversal -import ( - "strings" - - "github.com/northwesternmutual/grammes/query/cardinality" -) - // http://tinkerpop.apache.org/docs/current/reference/#addproperty-step // Property (sideEffect) unlike AddV() and AddE(), Property() is @@ -38,42 +32,11 @@ import ( // Property(interface{} (Object), interface{} (Object), ...interface{} (Object)) // Property(Cardinality, string (Object), interface{} (Object), ...interface{} (Object)) func (g String) Property(objOrCard interface{}, obj interface{}, params ...interface{}) String { - g = g.append(".property(") - - switch objOrCard.(type) { - case cardinality.Cardinality: - g = g.append(objOrCard.(cardinality.Cardinality).String()) - case string: - g = g.append("\"" + objOrCard.(string) + "\"") - default: - g = g.append(fmtStr("%v", objOrCard)) - } - - switch obj.(type) { - case string: - g = g.append(",\"" + strings.ReplaceAll(obj.(string), "\"", "\\\"") + "\"") - case int64, uint64: - g = g.append(fmtStr(",%dL", obj)) - case float32, float64: - g = g.append(fmtStr(",%fd", obj)) - default: - g = g.append(fmtStr(",%v", obj)) - } - - if len(params) > 0 { - for _, p := range params { - switch p.(type) { - case string: - g = g.append(",\"" + strings.ReplaceAll(p.(string), "\"", "\\\"") + "\"") - case int64, uint64: - g = g.append(fmtStr(",%dL", p)) - default: - g = g.append(fmtStr(",%v", p)) - } - } - } + fullParams := make([]interface{}, 0, len(params)+2) + fullParams = append(fullParams, objOrCard, obj) + fullParams = append(fullParams, params...) - g = g.append(")") + g.AddStep("property", fullParams...) return g } diff --git a/query/traversal/graph.go b/query/traversal/graph.go index 3a95989..aea285a 100755 --- a/query/traversal/graph.go +++ b/query/traversal/graph.go @@ -28,16 +28,8 @@ package traversal // Signatures: // V() // V(int...) -func (g String) V(params ...int) String { - // strParam := gatherInts(params...) - // g = g.append(fmtStr(".V(%v)", strParam)) - var p []interface{} - - for _, i := range params { - p = append(p, i) - } - - g.AddStep("V", p...) +func (g String) V(params ...interface{}) String { + g.AddStep("V", params...) return g } From 059981b86c6fc12e4e0b293c43f2c8a51eb5e82c Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Tue, 21 Feb 2023 11:51:40 +0500 Subject: [PATCH 13/16] replacing modules --- go.mod | 11 ++++------- go.sum | 11 +++-------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index f53bf08..d7c2b6b 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,13 @@ -module github.com/northwesternmutual/grammes +module github.com/Kaleidoscope-Inc/grammes go 1.13 require ( github.com/google/uuid v1.1.0 - github.com/gopherjs/gopherjs v0.0.0-20190309154008-847fc94819f9 // indirect github.com/gorilla/websocket v1.4.0 - github.com/pkg/errors v0.8.1 // indirect - github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac // indirect + github.com/northwesternmutual/grammes v1.2.0 github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff - github.com/stretchr/testify v1.3.0 // indirect - go.uber.org/atomic v1.3.2 // indirect - go.uber.org/multierr v1.1.0 // indirect go.uber.org/zap v1.9.1 ) + +replace github.com/northwesternmutual/grammes v1.2.0 => github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230122141751-f792e4382f6f diff --git a/go.sum b/go.sum index 96de978..e2c20aa 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,14 @@ +github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230122141751-f792e4382f6f h1:349cHev9pg5mC6WOifNdS6Io+gxOL9q0gM/riD89NjY= +github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230122141751-f792e4382f6f/go.mod h1:4VHtfaxVmMj1SBXs5ZFlcUwQPUBLcKdyNHaRUzT9nm0= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s= github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg= -github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v0.0.0-20190309154008-847fc94819f9 h1:Z0f701LpR4dqO92bP6TnIe3ZURClzJtBhds8R8u1HBE= github.com/gopherjs/gopherjs v0.0.0-20190309154008-847fc94819f9/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= -github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= @@ -17,12 +16,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY= -github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac h1:wbW+Bybf9pXxnCFAOWZTqkRjAc7rAIwo2e1ArUhiHxg= github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c h1:Ho+uVpkel/udgjbwB5Lktg9BtvJSh2DT0Hi6LPSyI2w= -github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff h1:86HlEv0yBCry9syNuylzqznKXDK11p6D0DT596yNMys= github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff/go.mod h1:KSQcGKpxUMHk3nbYzs/tIBAM2iDooCn0BmttHOJEbLs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= From 8767e621b9abeccb5ec695357337c931d25da119 Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Tue, 21 Feb 2023 15:33:41 +0500 Subject: [PATCH 14/16] updating module --- go.mod | 6 +++++- go.sum | 39 +++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index d7c2b6b..3a6eb71 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,12 @@ require ( github.com/google/uuid v1.1.0 github.com/gorilla/websocket v1.4.0 github.com/northwesternmutual/grammes v1.2.0 + github.com/pkg/errors v0.9.1 // indirect github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff + github.com/stretchr/testify v1.8.1 // indirect + go.uber.org/atomic v1.10.0 // indirect + go.uber.org/multierr v1.9.0 // indirect go.uber.org/zap v1.9.1 ) -replace github.com/northwesternmutual/grammes v1.2.0 => github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230122141751-f792e4382f6f +replace github.com/northwesternmutual/grammes v1.2.0 => github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230221065140-059981b86c6f diff --git a/go.sum b/go.sum index e2c20aa..318c8a1 100644 --- a/go.sum +++ b/go.sum @@ -1,31 +1,42 @@ -github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230122141751-f792e4382f6f h1:349cHev9pg5mC6WOifNdS6Io+gxOL9q0gM/riD89NjY= -github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230122141751-f792e4382f6f/go.mod h1:4VHtfaxVmMj1SBXs5ZFlcUwQPUBLcKdyNHaRUzT9nm0= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230221065140-059981b86c6f h1:8pA4TUmftwBiiD+Oalu80jW37Y6gW2aO7p+IqdcZSxc= +github.com/Kaleidoscope-Inc/grammes v1.2.1-0.20230221065140-059981b86c6f/go.mod h1:Sj+p5edaQt/FUNoNUqQfowy3IUq+WXkoFBEACWSO4AU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s= github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gopherjs/gopherjs v0.0.0-20190309154008-847fc94819f9 h1:Z0f701LpR4dqO92bP6TnIe3ZURClzJtBhds8R8u1HBE= -github.com/gopherjs/gopherjs v0.0.0-20190309154008-847fc94819f9/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac h1:wbW+Bybf9pXxnCFAOWZTqkRjAc7rAIwo2e1ArUhiHxg= -github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff h1:86HlEv0yBCry9syNuylzqznKXDK11p6D0DT596yNMys= github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff/go.mod h1:KSQcGKpxUMHk3nbYzs/tIBAM2iDooCn0BmttHOJEbLs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= -go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= +go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 9951ce08f8ddaf848767e7054bff890621876e47 Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Wed, 1 Mar 2023 00:20:27 +0500 Subject: [PATCH 15/16] adding custom connect --- gremconnect/websocket.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gremconnect/websocket.go b/gremconnect/websocket.go index a2b5c25..7cf351d 100755 --- a/gremconnect/websocket.go +++ b/gremconnect/websocket.go @@ -85,6 +85,40 @@ func (ws *WebSocket) Connect() error { return err } +func (ws *WebSocket) ConnectWithBufferSize(bufferSize int) error { + var err error + dialer := websocket.Dialer{ + WriteBufferSize: 1024 * bufferSize, // Set up for large messages. + ReadBufferSize: 1024 * bufferSize, // Set up for large messages. + HandshakeTimeout: 5 * time.Second, + } + + // Check if the host address already has the proper + // /gremlin endpoint at the end of it. If it doesn't + // then concatenate it to the end of the string. + // https://groups.google.com/forum/#!msg/gremlin-users/x4hiHsmTsHM/Xe4GcPtRCAAJ + if !strings.HasSuffix(ws.address, "/gremlin") { + ws.address = ws.address + "/gremlin" + } + + ws.conn, _, err = dialer.Dial(ws.address, http.Header{}) + + if err == nil { + ws.connected = true + + handler := func(appData string) error { + ws.Lock() + ws.connected = true + ws.Unlock() + return nil + } + + ws.conn.SetPongHandler(handler) + } + + return err +} + // IsConnected returns whether the given // websocket has an established connection. func (ws *WebSocket) IsConnected() bool { From 57559b8451dcb71bd40a94c667848c7b537d5126 Mon Sep 17 00:00:00 2001 From: Waleed Akram Khan Date: Wed, 1 Mar 2023 00:40:50 +0500 Subject: [PATCH 16/16] removing custom connect --- gremconnect/websocket.go | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/gremconnect/websocket.go b/gremconnect/websocket.go index 7cf351d..a2b5c25 100755 --- a/gremconnect/websocket.go +++ b/gremconnect/websocket.go @@ -85,40 +85,6 @@ func (ws *WebSocket) Connect() error { return err } -func (ws *WebSocket) ConnectWithBufferSize(bufferSize int) error { - var err error - dialer := websocket.Dialer{ - WriteBufferSize: 1024 * bufferSize, // Set up for large messages. - ReadBufferSize: 1024 * bufferSize, // Set up for large messages. - HandshakeTimeout: 5 * time.Second, - } - - // Check if the host address already has the proper - // /gremlin endpoint at the end of it. If it doesn't - // then concatenate it to the end of the string. - // https://groups.google.com/forum/#!msg/gremlin-users/x4hiHsmTsHM/Xe4GcPtRCAAJ - if !strings.HasSuffix(ws.address, "/gremlin") { - ws.address = ws.address + "/gremlin" - } - - ws.conn, _, err = dialer.Dial(ws.address, http.Header{}) - - if err == nil { - ws.connected = true - - handler := func(appData string) error { - ws.Lock() - ws.connected = true - ws.Unlock() - return nil - } - - ws.conn.SetPongHandler(handler) - } - - return err -} - // IsConnected returns whether the given // websocket has an established connection. func (ws *WebSocket) IsConnected() bool {