intro to mutating cypher

23
Cypher Query Language Chicago Graph Database Meet-Up Max De Marzi

Upload: max-de-marzi

Post on 10-May-2015

1.883 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Intro to Mutating Cypher

Cypher Query Language

Chicago Graph Database Meet-UpMax De Marzi

Page 2: Intro to Mutating Cypher

What is Cypher?

•Graph Query Language for Neo4j

•Aims to make querying simple

Page 3: Intro to Mutating Cypher

Design Decisions

Pattern matching

AA

BB CC

Page 4: Intro to Mutating Cypher

Design Decisions

Pattern matching

Page 5: Intro to Mutating Cypher

Design Decisions

Pattern matching

Page 6: Intro to Mutating Cypher

Design Decisions

Pattern matching

Page 7: Intro to Mutating Cypher

Design Decisions

Pattern matching

Page 8: Intro to Mutating Cypher

Design Decisions

ASCII-art patterns

() --> ()

Page 9: Intro to Mutating Cypher

Design Decisions

Directed relationship

(A) --> (B)

AA BB

Page 10: Intro to Mutating Cypher

Design Decisions

Undirected relationship

(A) -- (B)

AA BB

Page 11: Intro to Mutating Cypher

Design Decisions

specific relationships

A -[:LOVES]-> B

AA BBLOVES

Page 12: Intro to Mutating Cypher

Design Decisions

Joined paths

A --> B --> C

AA BB CC

Page 13: Intro to Mutating Cypher

Design Decisions

multiple paths

A --> B --> C, A --> C

AA

BB CC

A --> B --> C <-- A

Page 14: Intro to Mutating Cypher

Design Decisions

Optional relationships

A -[?]-> B

AA BB

Page 15: Intro to Mutating Cypher

Mutating CypherNew in Neo4j 1.8

Page 16: Intro to Mutating Cypher

Create Nodes

The Ninja Turtles

CypherCREATE turtle1 = {name : 'Donatello'}, turtle2 = {name : ‘Michelangelo'}, turtle3 = {name : ‘Raphael'}, turtle4 = {name : ‘Leonardo'}

Page 17: Intro to Mutating Cypher

Create Relationships

The Ninja Turtles are disciples of

Splinter

Cypher

START t1 = node(1), t2 = node(2), t3 = node(3), t4 = node(4)CREATE s = {name: ‘Splinter’ }, t1-[r:DISCIPLE]->s, t2-[r:DISCIPLE]->s, t3-[r:DISCIPLE]->s, t4-[r:DISCIPLE]->s

Page 18: Intro to Mutating Cypher

Delete Nodes

Shredder is defeated

CypherSTART  s = node:nodes(name = ‘Shredder’)DELETE s

Page 19: Intro to Mutating Cypher

Update Properties

Donatello uses the Bo StaffMichelangelo is always hungry

CypherSTART t1 = node(0), t2 = node(2)SET t1.weapon = ‘Bo Staff’, t2.hungry = ‘Yes’

Page 20: Intro to Mutating Cypher

Delete Properties

Michelangelo nom nom nom

CypherSTART t2 = node(2)DELETE t2.hungry

Page 21: Intro to Mutating Cypher

Using Relate

The Ninja Turtles love pizza

A pizza node and 4 relationships

are created

CypherSTART turtles = node(1,2,3,4)RELATE turtles-[r:LOVE]->pizza

Page 22: Intro to Mutating Cypher

Using Relate again

The Ninja Turtles love pizza

A pizza node with name “Supreme”

and 4 relationships are created

CypherSTART turtles = node(1,2,3,4)RELATE turtles-[r:LOVE]-(pizza {name:’Supreme’})

Page 23: Intro to Mutating Cypher

Questions?

maxdemarzi.com