Skip to content

Instantly share code, notes, and snippets.

@aseemk
Created October 27, 2012 20:57
Show Gist options
  • Save aseemk/3966223 to your computer and use it in GitHub Desktop.
Save aseemk/3966223 to your computer and use it in GitHub Desktop.
Neo4j mutable Cypher, e.g. creating comments (node + relationships + update stats)
results = @query _, """
START author=node({authorId}), target=node({targetId})
CREATE comment={commentData}
CREATE comment -[:#{@REL_AUTHOR} {relAuthorData}]-> author
CREATE comment <-[:#{@REL_COMMENT} {relTargetData}]- target
SET author.numCommentsBy = COALESCE(author.numCommentsBy?, 0) + 1
SET target.numComments = COALESCE(target.numComments?, 0) + 1
RETURN comment
""",
authorId: author.id
targetId: target.id
commentData: @_createNodeData(data)
relAuthorData: @_createRelationshipData()
relTargetData: @_createRelationshipData()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment