Skip to content

Commit

Permalink
change interface (#155)
Browse files Browse the repository at this point in the history
* change interface

* update go.mod

* format
  • Loading branch information
czpmango authored Jan 6, 2022
1 parent 2a2196d commit dcf3e5e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 94 deletions.
3 changes: 2 additions & 1 deletion box/generator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ 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=
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=
Expand Down
91 changes: 1 addition & 90 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dcf3e5e

Please sign in to comment.