Skip to content

Commit

Permalink
Added nested path tests to decoder & adjusted readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitawootten committed Jan 12, 2022
1 parent 3c35c9a commit 6799ff1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func main() {
EnableLogParams: false,
// enable open tracing. Ensure contexts have spans already. GoGM does not make root spans, only child spans
OpentracingEnabled: false,
// specify the method gogm will use to generate Load queries
LoadStrategy: gogm.PATH_LOAD_STRATEGY // set to SCHEMA_LOAD_STRATEGY for schema-aware queries which may reduce load on the database
}

// register all vertices and edges
Expand Down
66 changes: 66 additions & 0 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,4 +926,70 @@ func TestDecode2(t *testing.T) {
req.Equal(int64(55), *readin9.Id)
req.Equal("dasdfas", readin9.UUID)

// decode should be able to handle queries that return nested lists of paths, relationships, and nodes
decodeResultNested := [][]interface{}{
{
neo4j.Node{
Id: 18,
Labels: []string{"a"},
Props: map[string]interface{}{
"uuid": "2588baca-7561-43f8-9ddb-9c7aecf87284",
},
},
},
{
[]interface{}{
[]interface{}{
[]interface{}{
[]interface{}{
neo4j.Relationship{
Id: 0,
StartId: 19,
EndId: 18,
Type: "testm2o",
},
neo4j.Node{
Id: 19,
Labels: []string{"b"},
Props: map[string]interface{}{
"test_fielda": "1234",
"uuid": "b6d8c2ab-06c2-43d0-8452-89d6c4ec5d40",
},
},
},
},
[]interface{}{},
[]interface{}{
[]interface{}{
neo4j.Relationship{
Id: 1,
StartId: 18,
EndId: 19,
Type: "special_single",
Props: map[string]interface{}{
"test": "testing",
},
},
neo4j.Node{
Id: 19,
Labels: []string{"b"},
Props: map[string]interface{}{
"test_fielda": "1234",
"uuid": "b6d8c2ab-06c2-43d0-8452-89d6c4ec5d40",
},
},
},
},
},
[]interface{}{},
[]interface{}{},
},
},
}
var readinNested a
req.Nil(decode(gogm, newMockResult(decodeResultNested), &readinNested))
req.Equal("2588baca-7561-43f8-9ddb-9c7aecf87284", readinNested.UUID)
req.Len(readinNested.ManyA, 1)
req.Equal("b6d8c2ab-06c2-43d0-8452-89d6c4ec5d40", readinNested.ManyA[0].UUID)
req.Equal(readinNested.ManyA[0], readinNested.SingleSpecA.End, "Two rels should have the same node instance")
}
2 changes: 1 addition & 1 deletion integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func (i *IntegrationTestSuite) TestSchemaLoadStrategy() {
defer req.Nil(sess.Close())

// test raw query (verify SchemaLoadStrategy + Neo driver decoding)
query, err := SchemaLoadStrategyOne(i.gogm, "n", "a", "uuid", "uuid", false, 2, nil)
query, err := SchemaLoadStrategyOne(i.gogm, "n", "a", "uuid", "uuid", false, 1, nil)
req.Nil(err, "error generating SchemaLoadStrategy query")

cypher, err := query.ToCypher()
Expand Down

0 comments on commit 6799ff1

Please sign in to comment.