Skip to content

Commit

Permalink
updated to new driver, commented v3 test and updated to generic id
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Solender committed May 27, 2021
1 parent 5b2560e commit ed14e83
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 36 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 4 additions & 4 deletions interfacev2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 19 additions & 12 deletions load_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 10 additions & 7 deletions sessionv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ed14e83

Please sign in to comment.