From e0039bc438825c1f77ec8398714cd006a83c9aa1 Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Tue, 4 Jan 2022 17:31:13 +0800 Subject: [PATCH 1/3] change interface --- main.go | 91 +-------------------------------------------------------- 1 file changed, 1 insertion(+), 90 deletions(-) diff --git a/main.go b/main.go index 96c6bc2..914db4b 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,6 @@ import ( "github.com/vesoft-inc/nebula-console/cli" "github.com/vesoft-inc/nebula-console/printer" nebulago "github.com/vesoft-inc/nebula-go/v2" - nebula "github.com/vesoft-inc/nebula-go/v2/nebula" ) // Console side commands @@ -353,18 +352,7 @@ func loop(c cli.Cli) error { var t2 int64 = 0 for i := 0; i < g_repeats; i++ { start := time.Now() - // convert interface{} to nebula.Value - params := make(map[string]*nebula.Value) - for k, v := range parameterMap { - value, err := Base2Value(v) - if err != nil { - printConsoleResp(err.Error()) - return err - } - params[k] = value - } - - res, err := session.ExecuteWithParameter(line, params) + res, err := session.ExecuteWithParameter(line, parameterMap) if err != nil { return err } @@ -498,83 +486,6 @@ func validateFlags() { } } -// construct Slice to nebula.NList -func Slice2Nlist(list []interface{}) (*nebula.NList, error) { - sv := []*nebula.Value{} - var ret nebula.NList - for _, item := range list { - nv, er := Base2Value(item) - if er != nil { - return nil, er - } - sv = append(sv, nv) - } - ret.Values = sv - return &ret, nil -} - -// construct map to nebula.NMap -func Map2Nmap(m map[string]interface{}) (*nebula.NMap, error) { - var ret nebula.NMap - kvs := map[string]*nebula.Value{} - for k, v := range m { - nv, err := Base2Value(v) - if err != nil { - return nil, err - } - kvs[k] = nv - } - ret.Kvs = kvs - return &ret, nil -} - -// construct go-type to nebula.Value -func Base2Value(any interface{}) (value *nebula.Value, err error) { - value = nebula.NewValue() - if v, ok := any.(bool); ok { - value.BVal = &v - } else if v, ok := any.(int); ok { - ival := int64(v) - value.IVal = &ival - } else if v, ok := any.(float64); ok { - if v == float64(int64(v)) { - iv := int64(v) - value.IVal = &iv - } else { - value.FVal = &v - } - } else if v, ok := any.(float32); ok { - if v == float32(int64(v)) { - iv := int64(v) - value.IVal = &iv - } else { - fval := float64(v) - value.FVal = &fval - } - } else if v, ok := any.(string); ok { - value.SVal = []byte(v) - } else if any == nil { - nval := nebula.NullType___NULL__ - value.NVal = &nval - } else if v, ok := any.([]interface{}); ok { - nv, er := Slice2Nlist([]interface{}(v)) - if er != nil { - err = er - } - value.LVal = nv - } else if v, ok := any.(map[string]interface{}); ok { - nv, er := Map2Nmap(map[string]interface{}(v)) - if er != nil { - err = er - } - value.MVal = nv - } else { - // unsupport other Value type, use this function carefully - err = fmt.Errorf("Only support convert boolean/float/int/string/map/list to nebula.Value but %T", any) - } - return -} - var pool *nebulago.ConnectionPool var session *nebulago.Session From d5fa3bb4ededbdbdd22801feb76297a8c806889b Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Thu, 6 Jan 2022 10:17:52 +0800 Subject: [PATCH 2/3] update go.mod --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8c227f8..ffcfa44 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,6 @@ require ( github.com/jedib0t/go-pretty/v6 v6.0.5 github.com/jievince/liner v1.2.4-0.20211229025353-9af8863139ef github.com/mattn/go-runewidth v0.0.13 // indirect - github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211228055601-b5b11a36e453 + github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20220106021349-6ef61ed6077f golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect ) diff --git a/go.sum b/go.sum index 9d32fa8..bf020cc 100644 --- a/go.sum +++ b/go.sum @@ -41,6 +41,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211228055601-b5b11a36e453 h1:1rwe3LQVuTRUJBf4Gonc47+T3dCD29EzkrRaTzkUNdw= github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211228055601-b5b11a36e453/go.mod h1:YRIuog6zyRKz0SagwwTcqHXCPjJ4GfQelIl+/FgSC+Y= +github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20220106021349-6ef61ed6077f h1:3hUyg8U8FCYqDKsGr5LfIGr97l6KDVtLbY5XJF+oKq0= +github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20220106021349-6ef61ed6077f/go.mod h1:YRIuog6zyRKz0SagwwTcqHXCPjJ4GfQelIl+/FgSC+Y= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= From 5d5321b83da52df105555ea2e4ee8b23c5a345f2 Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Thu, 6 Jan 2022 10:18:48 +0800 Subject: [PATCH 3/3] format --- box/generator.go | 3 ++- go.sum | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/box/generator.go b/box/generator.go index 81af453..1037186 100644 --- a/box/generator.go +++ b/box/generator.go @@ -1,4 +1,5 @@ -//+build ignore +//go:build ignore +// +build ignore // A tool help to embed static files into a golang binary // Thanks for https://dev.to/koddr/the-easiest-way-to-embed-static-files-into-a-binary-file-in-your-golang-app-no-external-dependencies-43pc diff --git a/go.sum b/go.sum index bf020cc..5ee5660 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211228055601-b5b11a36e453 h1:1rwe3LQVuTRUJBf4Gonc47+T3dCD29EzkrRaTzkUNdw= -github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20211228055601-b5b11a36e453/go.mod h1:YRIuog6zyRKz0SagwwTcqHXCPjJ4GfQelIl+/FgSC+Y= github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20220106021349-6ef61ed6077f h1:3hUyg8U8FCYqDKsGr5LfIGr97l6KDVtLbY5XJF+oKq0= github.com/vesoft-inc/nebula-go/v2 v2.5.2-0.20220106021349-6ef61ed6077f/go.mod h1:YRIuog6zyRKz0SagwwTcqHXCPjJ4GfQelIl+/FgSC+Y= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=