It is possible to replace Neo4j commands with native Haskell functions.
There are of course differences because an EDSL is slightly less comfortable than the Neo4j DSL.
This is taken from https://neo4j.com/docs/cypher-refcard/current/ .
(n:Person)
Node with Person label.
node (labels [Person])
If you want to reuse the node use:
n where n = node (labels [Person])
(n:Person:Swedish)
Node with both Person and Swedish label.
node (labels [SwedishPerson])
In judyDB the labels partition the nodes. So every node is in only one partition. This has advantages in speed and memory efficiency and is good enough in most cases. If it should not be enough use where_ clause and query the secondary structure (having created it at the beginning).
(n:Person {name: $value})
Node with the declared properties.
node (labels [Person]) (where_ filt)
where filt x = name x == "value"
()-[r {name: $value}]-()
Matches relationships with the declared properties.
node anyNode --| named |-- node anyNode
where named = edge (whereE filt)
filt x = name x == "value"
(m)-->(n)
Relationship from m to n.
m --> n
where m = node anyNode
n = node anyNode
You have to say what m and n are
(m)--(n)
Relationship between m and n.
m ~~ n
where m = node anyNode
n = node anyNode
Like above, but undirected. Haskell uses --
for comments, so we have to use tildes: ~~
(m:Person)-->(n)
Node m labeled Person with relationship to n.
m --> n
where m = node (labels [Person])
n = node anyNode
(m)<-[:KNOWS]-(n)
Relationship of type KNOWS from m to n.
m <--| knows |-- n
where knows = edge (attr KNOWS)
(m)<-[:KNOWS|:LOVES]-(n)
Relationship of type KNOWS or of type LOVES from m to n.
m <--| knowsLoves |-- n
where knowsLoves = edge (orth KNOWS) (orth LOVES)
(m)-[r]->(n)
Bind the relationship to variable r.
m <--| r |-- n
where r = edge (whereE )
? If you bind it to something then you use it to somehow restrict the edges used.
(m)-[*1..5]->(n)
Variable length (between 1 and 5) path in relationships from m to n.
m --| r |--> n
where r = edge (1…5)
m --| r |--> n
where r = edge (1...5)
(m)-[*]->(n)
Variable length path of any number of relationships from m to n.
m --| r |--> n
where r = edge ***
(m)-[:KNOWS]->(n {property: $value})
A relationship of type KNOWS from a node m to a node n with the declared property.
TODO
shortestPath((n1:Person)-[*..6]-(n2:Person))
Find a single shortest path.
TODO
allShortestPath((n1:Person)-[*..6]-(n2:Person))
Find all shortest paths.
TODO
size((n)-->()-->())
Count the paths matching the pattern.
TODO
Neo4j | judy-graph-db | Comment |
---|---|---|
MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name = 'Alice' Node patterns can contain labels and properties. |
||
MATCH (n)-->(m) Any pattern can be used in MATCH. |
||
MATCH (n {name: 'Alice'})-->(m) Patterns with node properties. |
||
MATCH p = (n)-->(m) Assign a path to p. |
||
OPTIONAL MATCH (n)-[r]->(m) Optional pattern: nulls will be used for missing parts. |
Neo4j | judy-graph-db | Comment |
---|---|---|
WHERE n.property <> $value Use a predicate to filter. Note that WHERE is always part of a MATCH, OPTIONAL MATCH, WITH or START clause. Putting it after a different clause in a query will alter what it does. |
Neo4j | judy-graph-db | Comment |
---|---|---|
RETURN * Return the value of all variables. |
||
RETURN n AS columnName Use alias for result column name. |
||
RETURN DISTINCT n Return unique rows. |
||
ORDER BY n.property Sort the result. |
||
ORDER BY n.property DESC Sort the result in descending order. |
||
SKIP $skipNumber Skip a number of results. |
||
LIMIT $limitNumber Limit the number of results. |
||
SKIP $skipNumber LIMIT $limitNumber Skip results at the top and limit the number of results. |
||
RETURN count(*) The number of matching rows. See Aggregating Functions for more. |
Neo4j | judy-graph-db | Comment |
---|---|---|
CREATE (n {name: $value}) Create a node with the given properties. |
||
CREATE (n $map) Create a node with the given properties. |
||
UNWIND $listOfMaps AS properties CREATE (n) SET n = properties Create nodes with the given properties. |
||
CREATE (n)-[r:KNOWS]->(m) Create a relationship with the given type and direction; bind a variable to it. |
||
CREATE (n)-[:LOVES {since: $value}]->(m) Create a relationship with the given type, direction, and properties. |
Neo4j | judy-graph-db | Comment |
---|---|---|
SET n.property1 = $value1, n.property2 = $value2 Update or create a property. |
||
SET n = $map Set all properties. This will remove any existing properties. |
||
SET n += $map Add and update properties, while keeping existing ones. |
||
SET n:Person Adds a label Person to a node. |
Neo4j | judy-graph-db | Comment |
---|---|---|
Neo4j | judy-graph-db | Comment |
---|---|---|