summaryrefslogtreecommitdiffhomepage
path: root/cypher.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'cypher.html.markdown')
-rw-r--r--cypher.html.markdown81
1 files changed, 51 insertions, 30 deletions
diff --git a/cypher.html.markdown b/cypher.html.markdown
index 6efc0cec..2b8e9ac8 100644
--- a/cypher.html.markdown
+++ b/cypher.html.markdown
@@ -11,34 +11,37 @@ This tutorial assumes that you already know graph concepts like nodes and relati
[Read more here.](https://neo4j.com/developer/cypher-query-language/)
-`// There is just single-line comments in Cypher`
-
-
-
Nodes
---
**Represents a record in a graph.**
-**`()`** It's an empty *node*, to indicate that there is a *node*, but it's not relevant for the query.
+```()```
+It's an empty *node*, to indicate that there is a *node*, but it's not relevant for the query.
-**`(n)`** It's a *node* refered by the variable **n**, reusable in the query. It begins with lowercase and uses camelCase.
+```(n)```
+It's a *node* refered by the variable **n**, reusable in the query. It begins with lowercase and uses camelCase.
-**`(p:Person)`** You can add a *label* to your node, here **Person**. It's like a type / a class / a category. It begins with uppercase and uses camelCase.
+```(p:Person)```
+You can add a *label* to your node, here **Person**. It's like a type / a class / a category. It begins with uppercase and uses camelCase.
-**`(p:Person:Manager)`** A node can have many *labels*.
+```(p:Person:Manager)```
+A node can have many *labels*.
-**`(p:Person {name : 'Théo Gauchoux', age : 22})`** A node can have some *properties*, here **name** and **age**. It begins with lowercase and uses camelCase.
+```(p:Person {name : 'Théo Gauchoux', age : 22})```
+A node can have some *properties*, here **name** and **age**. It begins with lowercase and uses camelCase.
The types allowed in properties :
-* Numeric
-* Boolean
-* String
-* List of previous primitive types
-**Warning : there isn't datetime property in Cypher ! You can use String with a specific pattern or a Numeric from a specific date.**
+ - Numeric
+ - Boolean
+ - String
+ - List of previous primitive types
-**`p.name`** You can access to a property with the dot style.
+*Warning : there isn't datetime property in Cypher ! You can use String with a specific pattern or a Numeric from a specific date.*
+
+```p.name```
+You can access to a property with the dot style.
Relationships (or Edges)
@@ -46,13 +49,17 @@ Relationships (or Edges)
**Connects two nodes**
-**`[:KNOWS]`** It's a *relationship* with the *label* **KNOWS**. It's a *label* as the node's label. It begins with uppercase and use UPPER_SNAKE_CASE.
+```[:KNOWS]```
+It's a *relationship* with the *label* **KNOWS**. It's a *label* as the node's label. It begins with uppercase and use UPPER_SNAKE_CASE.
-**`[k:KNOWS]`** The same *relationship*, refered by the variable **k**, reusable in the query, but it's not necessary.
+```[k:KNOWS]```
+The same *relationship*, refered by the variable **k**, reusable in the query, but it's not necessary.
-**`[k:KNOWS {since:2017}]`** The same *relationship*, with *properties* (like *node*), here **since**.
+```[k:KNOWS {since:2017}]```
+The same *relationship*, with *properties* (like *node*), here **since**.
-**`[k:KNOWS*..4]`** It's a structural information to use in a *path* (seen later). Here, **\*..4** says "Match the pattern, with the relationship **k** which be repeated between 1 and 4 times.
+```[k:KNOWS*..4]```
+It's a structural information to use in a *path* (seen later). Here, **\*..4** says "Match the pattern, with the relationship **k** which be repeated between 1 and 4 times.
Paths
@@ -60,13 +67,17 @@ Paths
**The way to mix nodes and relationships.**
-**`(a:Person)-[:KNOWS]-[b:Person]`** A path describing that **a** and **b** know each other.
+```(a:Person)-[:KNOWS]-[b:Person]```
+A path describing that **a** and **b** know each other.
-**`(a:Person)-[:MANAGES]->[b:Person]`** A path can be directed. This path describes that **a** is the manager of **b**.
+```(a:Person)-[:MANAGES]->[b:Person]```
+A path can be directed. This path describes that **a** is the manager of **b**.
-**`(a:Person)-[:KNOWS]-[b:Person]-[:KNOWS]-[c:Person]`** You can chain multiple relationships. This path describes the friend of a friend.
+```(a:Person)-[:KNOWS]-[b:Person]-[:KNOWS]-[c:Person]```
+You can chain multiple relationships. This path describes the friend of a friend.
-**`(a:Person)-[:MANAGES]->[b:Person]-[:MANAGES]->[c:Person]`** A chain can also be directed. This path describes that **a** is the boss of **b** and the big boss of **c**.
+```(a:Person)-[:MANAGES]->[b:Person]-[:MANAGES]->[c:Person]```
+A chain can also be directed. This path describes that **a** is the boss of **b** and the big boss of **c**.
Patterns often used (from Neo4j doc) :
@@ -85,6 +96,7 @@ path = shortestPath( (user)-[:KNOWS*..5]-(other) )
```
+
Create queries
---
@@ -148,6 +160,7 @@ WHERE a.name = "Jacquie" AND b.name = "Michel"
CREATE (a)-[:KNOWS]-(b)
```
+
Update queries
---
@@ -179,6 +192,7 @@ WHERE p.name = "Théo Gauchoux"
SET p:Internship
```
+
Delete queries
---
@@ -212,17 +226,24 @@ DELETE n, r
```
*Seriously, it's the `rm -rf /` of Cypher !*
+
Other useful clauses
---
-**`PROFILE`** Before a query, show the execution plan of it.
-**`COUNT(e)`** Count entities (nodes or relationships) matching **e**.
-**`LIMIT x`** Limit the result to the x first results.
+```PROFILE```
+Before a query, show the execution plan of it.
+
+```COUNT(e)```
+Count entities (nodes or relationships) matching **e**.
+
+```LIMIT x```
+Limit the result to the x first results.
+
Special hints
---
-* You can execute a Cypher script stored in a **.cql** file directly in Neo4j (it's an import). However, you can't have multiple statements in this file (separed by **;**).
-* Use the Neo4j shell to write Cypher, it's really awesome.
-* The Cypher will be the standard query language for all graph databases (known as **OpenCypher**).
-
+- There is just single-line comments in Cypher, with double-slash : // Comments
+- You can execute a Cypher script stored in a **.cql** file directly in Neo4j (it's an import). However, you can't have multiple statements in this file (separed by **;**).
+- Use the Neo4j shell to write Cypher, it's really awesome.
+- The Cypher will be the standard query language for all graph databases (known as **OpenCypher**).