You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are doing a project in Node.js,- but I plan to do the same in Go.
I do this to measure the effort going into doing this in Go vs Node.js and also difference in performance.
The Node.js implementation uses a BOLT-driver and I have mostly kind of copied the queries.
This query works fine for Node.js and BOLT,- but not for Go and Neoism. I have also ran the query manually in the browser directly against a Neo4J-instance (of course with replacements for the parameters).
result := []struct {
Hierarchy neoism.Node
Ous []neoism.Node
}{}
query := neoism.CypherQuery{
Statement: ``MERGE (hierarchy:Hierarchy {id: {hierarchyId}})
SET hierarchy.user = {user}
SET hierarchy.timestamp = {timestamp}
WITH hierarchy, {ouIds} AS ids
MATCH (hierarchy)-[h:has]->(ouId:OuId) WHERE NOT ouId.ouId IN ids
DELETE h
WITH hierarchy, ids
UNWIND ids AS id
MERGE (ouId:OuId {ouId: id})
WITH hierarchy, ouId
MATCH (hierarchy) WHERE NOT (hierarchy)-[:has]->(ouId)
CREATE (hierarchy)-[:has]->(ouId)
RETURN
hierarchy,
COLLECT(DISTINCT ouId) AS ous;``,
Parameters: neoism.Props{
"hierarchyId": h, // String
"user": hierarchy.LastModified.User, // String
"timestamp": modified.UnixNano(), // int64
"ouIds": hierarchy.Ous, // [int64, int64, ... ]
},
Result: &result,
}
qs := []*neoism.CypherQuery{}
var tx *neoism.Tx
if tx, err = db.Begin(qs); err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(model.ErrorResponse{Error: err})
return
}
if err = db.Cypher(&query); err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(model.ErrorResponse{Error: errors.New("Query failed!")})
return
}
if err = tx.Commit(); err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(model.ErrorResponse{Error: err})
return
}
if len(result) == 0 {
log.Printf("No results!\n")
w.WriteHeader(http.StatusInternalServerError)
return
}
The hierarchy-node is created in the database, but the rest is ignored. Commit also seems to work.
On the Go side the only symptom I get is that result is empty.
Am I doing something very wrong?
The text was updated successfully, but these errors were encountered:
Sorry for replying on my own question,- but I have seemed to have found a solution to my problem.
There was probably a corner-case, and adding OPTIONAL MATCH solved my problem.
query := neoism.CypherQuery{
Statement: `MERGE (hierarchy:Hierarchy {id: {hierarchyId}})
SET hierarchy.user = {user}
SET hierarchy.timestamp = {timestamp}
WITH hierarchy, {ouIds} AS ids
OPTIONAL MATCH (hierarchy)-[h:has]->(ouId:OuId) WHERE NOT ouId.ouId IN ids
DELETE h
WITH hierarchy, ids
UNWIND ids AS id
MERGE (ouId:OuId {ouId: id})
WITH hierarchy, ouId
OPTIONAL MATCH (hierarchy) WHERE NOT (hierarchy)-[:has]->(ouId)
CREATE (hierarchy)-[:has]->(ouId)
RETURN
hierarchy,
COLLECT(DISTINCT ouId) AS ous;`,
Parameters: neoism.Props{
"hierarchyId": h,
"user": hierarchy.LastModified.User,
"timestamp": modified.UnixNano(),
"ouIds": hierarchy.Ous,
},
Result: &result,
}
Hello
We are doing a project in Node.js,- but I plan to do the same in Go.
I do this to measure the effort going into doing this in Go vs Node.js and also difference in performance.
The Node.js implementation uses a BOLT-driver and I have mostly kind of copied the queries.
This query works fine for Node.js and BOLT,- but not for Go and Neoism. I have also ran the query manually in the browser directly against a Neo4J-instance (of course with replacements for the parameters).
The hierarchy-node is created in the database, but the rest is ignored. Commit also seems to work.
On the Go side the only symptom I get is that result is empty.
Am I doing something very wrong?
The text was updated successfully, but these errors were encountered: