From ed14e8347d63ec0aed9e3917b27cd8e4bb227a82 Mon Sep 17 00:00:00 2001 From: Eric Solender Date: Thu, 27 May 2021 13:59:24 -0400 Subject: [PATCH] updated to new driver, commented v3 test and updated to generic id --- .github/workflows/go.yml | 22 +++++++++++----------- go.mod | 2 +- go.sum | 2 ++ interfacev2.go | 8 ++++---- load_strategy.go | 31 +++++++++++++++++++------------ session.go | 2 +- sessionv2.go | 17 ++++++++++------- 7 files changed, 48 insertions(+), 36 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0a20438..c55ccfc 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -54,17 +54,17 @@ jobs: - name: Run Unit Tests run: go test ./... -cover -short - - name: Start Neo4j V3 Docker - run: | - docker-compose -f .github/docker-compose-v3.yaml up -d - - name: Wait for neo4j v3 to be ready - run: | - sleep 45 - - name: Run Integration Test on V3 - run: go test ./... -cover -run Integration - - name: Stop Neo4j Docker on v3 - run: | - docker-compose -f .github/docker-compose-v3.yaml down --remove-orphans +# - name: Start Neo4j V3 Docker +# run: | +# docker-compose -f .github/docker-compose-v3.yaml up -d +# - name: Wait for neo4j v3 to be ready +# run: | +# sleep 45 +# - name: Run Integration Test on V3 +# run: go test ./... -cover -run Integration +# - name: Stop Neo4j Docker on v3 +# run: | +# docker-compose -f .github/docker-compose-v3.yaml down --remove-orphans - name: Start Neo4j V4 Docker run: | diff --git a/go.mod b/go.mod index e87faaf..c65c500 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/google/uuid v1.1.1 github.com/kr/pretty v0.1.0 // indirect github.com/mindstand/go-cypherdsl v0.2.0 - github.com/neo4j/neo4j-go-driver/v4 v4.3.0-rc2 + github.com/neo4j/neo4j-go-driver/v4 v4.3.0 github.com/opentracing/opentracing-go v1.2.0 github.com/sirupsen/logrus v1.6.0 // indirect github.com/stretchr/objx v0.2.0 // indirect diff --git a/go.sum b/go.sum index 5a26703..9bfa909 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ github.com/mindstand/go-cypherdsl v0.2.0 h1:/B6A8DhWk2RksdJxruy3+ii3Hvrr5JU+2vL3 github.com/mindstand/go-cypherdsl v0.2.0/go.mod h1:swzbrSTuq3CRgFglg3aVThG9GBQmHXz6AY81q9mRMto= github.com/neo4j/neo4j-go-driver/v4 v4.3.0-rc2 h1:V1GaSLHRo3665JVe9PkPqttX/EAE8moa2Oh4Ttld7iY= github.com/neo4j/neo4j-go-driver/v4 v4.3.0-rc2/go.mod h1:5O/gk/AqFeu5CkRgsk3SAzSiPomlVZEHGgOrGGJbcMk= +github.com/neo4j/neo4j-go-driver/v4 v4.3.0 h1:L0YT6c2FfYmhdi6zvYXhXMLzXf6T4wourihW0NmRUDI= +github.com/neo4j/neo4j-go-driver/v4 v4.3.0/go.mod h1:5O/gk/AqFeu5CkRgsk3SAzSiPomlVZEHGgOrGGJbcMk= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= diff --git a/interfacev2.go b/interfacev2.go index 39a62a2..549e12d 100644 --- a/interfacev2.go +++ b/interfacev2.go @@ -55,16 +55,16 @@ type TransactionV2 interface { type ogmFunctions interface { //load single object - Load(ctx context.Context, respObj interface{}, id string) error + Load(ctx context.Context, respObj , id interface{},) error //load object with depth - LoadDepth(ctx context.Context, respObj interface{}, id string, depth int) error + LoadDepth(ctx context.Context, respObj , id interface{}, depth int) error //load with depth and filter - LoadDepthFilter(ctx context.Context, respObj interface{}, id string, depth int, filter *dsl.ConditionBuilder, params map[string]interface{}) error + LoadDepthFilter(ctx context.Context,respObj , id interface{}, depth int, filter *dsl.ConditionBuilder, params map[string]interface{}) error //load with depth, filter and pagination - LoadDepthFilterPagination(ctx context.Context, respObj interface{}, id string, depth int, filter dsl.ConditionOperator, params map[string]interface{}, pagination *Pagination) error + LoadDepthFilterPagination(ctx context.Context, respObj , id interface{}, depth int, filter dsl.ConditionOperator, params map[string]interface{}, pagination *Pagination) error //load slice of something LoadAll(ctx context.Context, respObj interface{}) error diff --git a/load_strategy.go b/load_strategy.go index 250af87..474da90 100644 --- a/load_strategy.go +++ b/load_strategy.go @@ -70,7 +70,7 @@ func PathLoadStrategyMany(variable, label string, depth int, additionalConstrain } // PathLoadStrategyOne loads one object using path strategy -func PathLoadStrategyOne(variable, label string, depth int, additionalConstraints dsl.ConditionOperator) (dsl.Cypher, error) { +func PathLoadStrategyOne(variable, label, fieldOn, paramName string, isGraphId bool, depth int, additionalConstraints dsl.ConditionOperator) (dsl.Cypher, error) { if variable == "" { return nil, errors.New("variable name cannot be empty") } @@ -96,20 +96,27 @@ func PathLoadStrategyOne(variable, label string, depth int, additionalConstraint builder := dsl.QB(). Match(path.Build()) - if additionalConstraints != nil { - builder = builder.Where(additionalConstraints.And(&dsl.ConditionConfig{ - Name: variable, - Field: "uuid", - ConditionOperator: dsl.EqualToOperator, - Check: dsl.ParamString("$uuid"), - })) + var condition *dsl.ConditionConfig + if isGraphId { + condition = &dsl.ConditionConfig{ + FieldManipulationFunction: "ID", + Name: variable, + ConditionOperator: dsl.EqualToOperator, + Check: dsl.ParamString("$" + paramName), + } } else { - builder = builder.Where(dsl.C(&dsl.ConditionConfig{ + condition = &dsl.ConditionConfig{ Name: variable, - Field: "uuid", + Field: fieldOn, ConditionOperator: dsl.EqualToOperator, - Check: dsl.ParamString("$uuid"), - })) + Check: dsl.ParamString("$" + paramName) , + } + } + + if additionalConstraints != nil { + builder = builder.Where(additionalConstraints.And(condition)) + } else { + builder = builder.Where(dsl.C(condition)) } return builder.Return(false, dsl.ReturnPart{Name: "p"}), nil diff --git a/session.go b/session.go index e22cd2b..5b1f710 100644 --- a/session.go +++ b/session.go @@ -219,7 +219,7 @@ func (s *Session) LoadDepthFilterPagination(respObj interface{}, id string, dept //make the query based off of the load strategy switch s.LoadStrategy { case PATH_LOAD_STRATEGY: - query, err = PathLoadStrategyOne(varName, respObjName, depth, filter) + query, err = PathLoadStrategyOne(varName, respObjName, "uuid", "uuid", false, depth, filter) if err != nil { return err } diff --git a/sessionv2.go b/sessionv2.go index 16a6068..3855acc 100644 --- a/sessionv2.go +++ b/sessionv2.go @@ -175,7 +175,7 @@ func (s *SessionV2Impl) Commit(ctx context.Context) error { return nil } -func (s *SessionV2Impl) Load(ctx context.Context, respObj interface{}, id string) error { +func (s *SessionV2Impl) Load(ctx context.Context, respObj , id interface{}) error { var span opentracing.Span if ctx != nil && s.gogm.config.OpentracingEnabled { span, ctx = opentracing.StartSpanFromContext(ctx, "gogm.SessionV2Impl.Load") @@ -187,7 +187,7 @@ func (s *SessionV2Impl) Load(ctx context.Context, respObj interface{}, id string return s.LoadDepthFilterPagination(ctx, respObj, id, s.DefaultDepth, nil, nil, nil) } -func (s *SessionV2Impl) LoadDepth(ctx context.Context, respObj interface{}, id string, depth int) error { +func (s *SessionV2Impl) LoadDepth(ctx context.Context, respObj , id interface{}, depth int) error { var span opentracing.Span if ctx != nil && s.gogm.config.OpentracingEnabled { span, ctx = opentracing.StartSpanFromContext(ctx, "gogm.SessionV2Impl.LoadDepth") @@ -199,7 +199,7 @@ func (s *SessionV2Impl) LoadDepth(ctx context.Context, respObj interface{}, id s return s.LoadDepthFilterPagination(ctx, respObj, id, depth, nil, nil, nil) } -func (s *SessionV2Impl) LoadDepthFilter(ctx context.Context, respObj interface{}, id string, depth int, filter *dsl.ConditionBuilder, params map[string]interface{}) error { +func (s *SessionV2Impl) LoadDepthFilter(ctx context.Context, respObj , id interface{}, depth int, filter *dsl.ConditionBuilder, params map[string]interface{}) error { var span opentracing.Span if ctx != nil && s.gogm.config.OpentracingEnabled { span, ctx = opentracing.StartSpanFromContext(ctx, "gogm.SessionV2Impl.LoadDepthFilter") @@ -211,7 +211,7 @@ func (s *SessionV2Impl) LoadDepthFilter(ctx context.Context, respObj interface{} return s.LoadDepthFilterPagination(ctx, respObj, id, depth, filter, params, nil) } -func (s *SessionV2Impl) LoadDepthFilterPagination(ctx context.Context, respObj interface{}, id string, depth int, filter dsl.ConditionOperator, params map[string]interface{}, pagination *Pagination) error { +func (s *SessionV2Impl) LoadDepthFilterPagination(ctx context.Context, respObj , id interface{}, depth int, filter dsl.ConditionOperator, params map[string]interface{}, pagination *Pagination) error { var span opentracing.Span if ctx != nil && s.gogm.config.OpentracingEnabled { span, ctx = opentracing.StartSpanFromContext(ctx, "gogm.SessionV2Impl.LoadDepthFilterPagination") @@ -239,10 +239,13 @@ func (s *SessionV2Impl) LoadDepthFilterPagination(ctx context.Context, respObj i var query dsl.Cypher var err error + paramName := "idprm" + isGraphId := s.gogm.pkStrategy.StrategyName == DefaultPrimaryKeyStrategy.StrategyName + field := s.gogm.pkStrategy.DBName //make the query based off of the load strategy switch s.LoadStrategy { case PATH_LOAD_STRATEGY: - query, err = PathLoadStrategyOne(varName, respObjName, depth, filter) + query, err = PathLoadStrategyOne(varName, respObjName, field, paramName, isGraphId, depth, filter) if err != nil { return err } @@ -271,10 +274,10 @@ func (s *SessionV2Impl) LoadDepthFilterPagination(ctx context.Context, respObj i if params == nil { params = map[string]interface{}{ - "uuid": id, + paramName: id, } } else { - params["uuid"] = id + params[paramName] = id } cyp, err := query.ToCypher()