Skip to content

Instantly share code, notes, and snippets.

@tomasonjo
Last active March 12, 2017 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomasonjo/d0a08dcfc3c1973a79a7595a0d7081a6 to your computer and use it in GitHub Desktop.
Save tomasonjo/d0a08dcfc3c1973a79a7595a0d7081a6 to your computer and use it in GitHub Desktop.
a set of rules, that will allow you to query Neo4j faster and more fun
Rules for labels
1. We use labels to group entities together -- (:Person),(:Company)
2. We use additional labels as a preprocessed way of filtering nodes faster -- (:Person:Expert),(:Company:VIP)
3. We can use labels for marking steps in our process -- (:Order:ExportedToElastic),(:Order:Error)
**************************************************************************************************************************************
Rules for date format
1. Neo4j does not support date format out of the box
2. Parse all dates to unix epoch time in seconds or miliseconds
3. Pick seconds or miliseconds and be consistent
4. Use (days * hours * minutes * seconds) in calculations for cleannes of the code
******************************************************************************************************************************
Rules for Location/timeseries (hiearchical) trees
1. All relationships are directed from children to parents, going up the hiearchy
2. We have a single type for all relationships. (PARENT...;FROM...)
2. Every node has a single outgoing relationship to it’s parent.
3. Every node has one or multiple incoming relationships from its children.
******************************************************************************************************************************
Triggers for automation
CALL apoc.trigger.add('timestampNodes','UNWIND {createdNodes} AS n SET n.created_at = timestamp()', {phase:'after'});
CALL apoc.trigger.add('timestampRels','UNWIND {createdRelationships} AS n SET n.created_at = timestamp()', {phase:'after'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment