Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from mindstand/driver_update
Browse files Browse the repository at this point in the history
Driver update
  • Loading branch information
Eric Solender authored May 24, 2020
2 parents ed2619b + 800b091 commit 86a9065
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 78 deletions.
12 changes: 6 additions & 6 deletions clause.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package go_cypherdsl

import neo "github.com/mindstand/golang-neo4j-bolt-driver"
import (
"github.com/mindstand/go-bolt/connection"
)

type Cypher interface {
Match
Expand Down Expand Up @@ -94,10 +96,8 @@ type CustomCypher interface {
}

type QueryCompleter interface {
WithNeo(conn *neo.BoltConn) Cypher
Query(params map[string]interface{}) (neo.Rows, error)
Exec(params map[string]interface{}) (neo.Result, error)
WithNeo(conn connection.IQuery) Cypher
Query(params map[string]interface{}) ([][]interface{}, error)
Exec(params map[string]interface{}) (connection.IResult, error)
ToCypher() (string, error)
AddToPreparedStatement(params map[string]interface{}) error
ExecutePreparedStatements() ([]neo.Result, error)
}
53 changes: 12 additions & 41 deletions cypher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package go_cypherdsl
import (
"errors"
"fmt"
neo "github.com/mindstand/golang-neo4j-bolt-driver"
"github.com/mindstand/go-bolt/connection"
"strings"
)

Expand All @@ -19,7 +19,7 @@ type QueryBuilder struct {

preparedStatements []stmt

conn *neo.BoltConn
conn connection.IQuery
}

func QB() *QueryBuilder {
Expand Down Expand Up @@ -273,7 +273,7 @@ func (q *QueryBuilder) Cypher(c string) Cypher {
return q
}

func (q *QueryBuilder) WithNeo(conn *neo.BoltConn) Cypher {
func (q *QueryBuilder) WithNeo(conn connection.IQuery) Cypher {
if conn == nil {
q.addError(errors.New("connection can not be nil"))
return q
Expand All @@ -284,7 +284,7 @@ func (q *QueryBuilder) WithNeo(conn *neo.BoltConn) Cypher {
return q
}

func (q *QueryBuilder) Query(params map[string]interface{}) (neo.Rows, error) {
func (q *QueryBuilder) Query(params map[string]interface{}) ([][]interface{}, error) {
if q.conn == nil {
return nil, errors.New("connection not specified")
}
Expand All @@ -301,10 +301,15 @@ func (q *QueryBuilder) Query(params map[string]interface{}) (neo.Rows, error) {

log.Debugf("Executing '%s' with params '%v'", query, params)

return q.conn.QueryNeo(query, params)
rows, _, err := q.conn.Query(query, params)
if err != nil {
return nil, err
}

return rows, nil
}

func (q *QueryBuilder) Exec(params map[string]interface{}) (neo.Result, error) {
func (q *QueryBuilder) Exec(params map[string]interface{}) (connection.IResult, error) {
if q.conn == nil {
return nil, errors.New("connection not specified")
}
Expand All @@ -321,7 +326,7 @@ func (q *QueryBuilder) Exec(params map[string]interface{}) (neo.Result, error) {

log.Debugf("Executing '%s' with params '%v'", query, params)

return q.conn.ExecNeo(query, params)
return q.conn.Exec(query, params)
}

func (q *QueryBuilder) ToCypher() (string, error) {
Expand Down Expand Up @@ -360,37 +365,3 @@ func (q *QueryBuilder) build() (string, error) {

return strings.TrimSuffix(query, " "), nil
}

func (q *QueryBuilder) AddToPreparedStatement(params map[string]interface{}) error {
query, err := q.build()
if err != nil {
return err
}

if q.preparedStatements == nil {
q.preparedStatements = []stmt{}
}

q.preparedStatements = append(q.preparedStatements, stmt{
Query: query,
Params: params,
})

return nil
}

func (q *QueryBuilder) ExecutePreparedStatements() ([]neo.Result, error) {
if q.preparedStatements == nil || len(q.preparedStatements) == 0 {
return nil, errors.New("no statements are prepared")
}

var queries []string
var params []map[string]interface{}

for _, statement := range q.preparedStatements {
queries = append(queries, statement.Query)
params = append(params, statement.Params)
}

return q.conn.ExecPipeline(queries, params...)
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.12

require (
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/mindstand/golang-neo4j-bolt-driver v0.0.0-20191030200006-d15c1c182165
github.com/mindstand/go-bolt v0.2.1-0.20200414154543-dd7499698d09
github.com/sirupsen/logrus v1.4.2
github.com/stretchr/testify v1.3.0
github.com/stretchr/testify v1.5.1
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ github.com/jolestar/go-commons-pool v2.0.0+incompatible/go.mod h1:ChJYIbIch0DMCS
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/mindstand/golang-neo4j-bolt-driver v0.0.0-20190907193812-b661fdf3c801 h1:nJAIXtpjPMojl+3TkZbu1vI6LyxfZ/VCPCgqH2FZvNQ=
github.com/mindstand/golang-neo4j-bolt-driver v0.0.0-20190907193812-b661fdf3c801/go.mod h1:prnROpf8DMlvFp57nUI0KaA8XnLKYyG/OORzgEOrJp0=
github.com/mindstand/golang-neo4j-bolt-driver v0.0.0-20190917210539-9477821dd010 h1:WBcwBI6Zc0QJIDWg5P5HpHBFD5u4sn8SucOP4EHlHyk=
github.com/mindstand/golang-neo4j-bolt-driver v0.0.0-20190917210539-9477821dd010/go.mod h1:SJGjyfk/mgTjbZOn3dHrpA3IqB5M1jTF0nsnh3dFXpM=
github.com/mindstand/golang-neo4j-bolt-driver v0.0.0-20190925190017-eca83d3ce35c h1:6jP0r3PDFjQgvcCKTCVsIFO40giVse1/Btj7BFlVg6U=
github.com/mindstand/golang-neo4j-bolt-driver v0.0.0-20190925190017-eca83d3ce35c/go.mod h1:SJGjyfk/mgTjbZOn3dHrpA3IqB5M1jTF0nsnh3dFXpM=
github.com/mindstand/golang-neo4j-bolt-driver v0.0.0-20191030200006-d15c1c182165 h1:r3B25jDadcUDN6QfyDhLpQ4Offefy1DtDHpxbiqq+m8=
github.com/mindstand/golang-neo4j-bolt-driver v0.0.0-20191030200006-d15c1c182165/go.mod h1:SJGjyfk/mgTjbZOn3dHrpA3IqB5M1jTF0nsnh3dFXpM=
github.com/mindstand/go-bolt v0.2.1-0.20200414154543-dd7499698d09 h1:mHyx0Fi0XYb3WXio8Og3w2gyWk1DKWrcyIELPmoIljM=
github.com/mindstand/go-bolt v0.2.1-0.20200414154543-dd7499698d09/go.mod h1:QHuPo43WBka6lBRuQv/ZsAxIHXgzuL+tOt1X9AL3WOw=
github.com/mindstand/gotime v0.0.0-20200414142228-237d9416b724 h1:SOnJCXp+mG8BQjx02AinZBhtVHT4ElVwiJZbDXKcy8s=
github.com/mindstand/gotime v0.0.0-20200414142228-237d9416b724/go.mod h1:DzECeSxMVcU5J1CTiyIjdI/+Q8TJWhdo96Vb1OpY41Q=
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/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 h1:4y9KwBHBgBNwDbtu44R5o1fdOCQUEXhbk/P4A9WmJq0=
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
22 changes: 3 additions & 19 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package go_cypherdsl
import (
"errors"
"fmt"
neo "github.com/mindstand/golang-neo4j-bolt-driver"
"reflect"
"strings"
)
Expand Down Expand Up @@ -62,12 +61,7 @@ func cypherizeInterface(i interface{}) (string, error) {
return "", errors.New("invalid type " + k.String())
}

func RowsToStringArray(rows neo.Rows) ([]string, error) {
data, _, err := rows.All()
if err != nil {
return nil, err
}

func RowsToStringArray(data [][]interface{}) ([]string, error) {
//check to make sure its not empty
if data == nil || len(data) == 0 || len(data[0]) == 0 {
return []string{}, nil
Expand Down Expand Up @@ -95,12 +89,7 @@ func RowsToStringArray(rows neo.Rows) ([]string, error) {
return toReturn, nil
}

func RowsTo2dStringArray(rows neo.Rows) ([][]string, error) {
data, _, err := rows.All()
if err != nil {
return nil, err
}

func RowsTo2dStringArray(data [][]interface{}) ([][]string, error) {
if len(data) != 0 && len(data[0]) != 0 {
toReturn := make([][]string, len(data))

Expand All @@ -117,13 +106,8 @@ func RowsTo2dStringArray(rows neo.Rows) ([][]string, error) {
}
}
}
return toReturn, rows.Close()
return toReturn, nil
} else {
return [][]string{}, nil
}
}

func RowsTo2DInterfaceArray(rows neo.Rows) ([][]interface{}, error) {
data, _, err := rows.All()
return data, err
}

0 comments on commit 86a9065

Please sign in to comment.