From 5cff0830c5e4266345ec708c9b739b92cebd8e11 Mon Sep 17 00:00:00 2001 From: thinkofher Date: Fri, 23 Jul 2021 16:09:05 +0200 Subject: [PATCH] Add new type that can be parametrized. This commit adds new type: "int64" that can be used by (*Graph).ParameterizedQuery method. According to the "Cypher Coverage" section from RedisGraph documentation: 64-bit signed integer is supported literal type. This change will allow, for example, to use time.Now().Unix() as parameter for previously mentioned ParameterizedQuery. Before this change, using int64 as parameter for ParameterizedQuery result with panic, although using int64 is very common when writing go code. --- client_test.go | 9 ++++++--- utils.go | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client_test.go b/client_test.go index 44ed0a3..233dcfd 100644 --- a/client_test.go +++ b/client_test.go @@ -420,10 +420,13 @@ func TestUtils(t *testing.T) { res = ToString(true) assert.Equal(t, res, "true") - var arr = []interface{}{1,2,3,"boom"} + res = ToString(int64(10)) + assert.Equal(t, res, "10") + + var arr = []interface{}{1, 2, 3, int64(4), "boom"} res = ToString(arr) - assert.Equal(t, res, "[1,2,3,\"boom\"]") - + assert.Equal(t, res, "[1,2,3,4,\"boom\"]") + jsonMap := make(map[string]interface{}) jsonMap["object"] = map[string]interface{} {"foo": 1} res = ToString(jsonMap) diff --git a/utils.go b/utils.go index 3cc2aad..bd66d2e 100644 --- a/utils.go +++ b/utils.go @@ -48,6 +48,8 @@ func ToString(i interface{}) string { return strconv.Quote(s) case int: return strconv.Itoa(i.(int)) + case int64: + return strconv.FormatInt(i.(int64), 10) case float64: return strconv.FormatFloat(i.(float64), 'f', -1, 64) case bool: