cypher는 Neo4j사에서 만든 선언적 그래프 질의어이다. Property Graph 모델에 기반을 두며, 노드와 엣지의 표준 그래프 요소들에 레이블(label)과 프로퍼티(property)를 추가해서 데이터베이스화 할 수 있다.
CREATE (ee:Person { name: "Emil", from: "Sweden", klout: 99 }),
(js:Person { name: "Johan", from: "Sweden", learn: "surfing" }),
(ir:Person { name: "Ian", from: "England", title: "author" }),
(rvb:Person { name: "Rik", from: "Belgium", pet: "Orval" }),
(ally:Person { name: "Allison", from: "California", hobby: "surfing" }),
(ee)-[:KNOWS {since: 2001}]->(js),(ee)-[:KNOWS {rating: 5}]->(ir),
(js)-[:KNOWS]->(ir),(js)-[:KNOWS]->(rvb),
(ir)-[:KNOWS]->(js),(ir)-[:KNOWS]->(ally),
(rvb)-[:KNOWS]->(ally)
MATCH (n) RETURN n
MATCH (n:Person {name:"Emil"}) RETURN n;
MATCH (n:Person) WHERE name = "Emil" RETURN n;
MATCH (ee:Person)-[:KNOWS]-(friends) WHERE ee.name = "Emil" RETURN ee, friends
// from 프로퍼티가 있는 Person 조회
MATCH (ee:Person) WHERE exists(ee.from) RETURN ee
Aggregating functions
String matching functions
MATCH (ee:Person)-[:KNOWS]-(friends) WHERE ee.name = "Ian"
RETURN DISTINCT friends.name, friends.from
ORDER BY friends.name
SKIP 1 LIMIT 2
MATCH (ee:Person {from:"Sweden"}) SET ee.age = 30 RETURN ee
MATCH (ee:Person {name:"Ian"}) REMOVE ee.title RETURN ee
MATCH (ee:Person {name:"Rik"}) DETACH DELETE ee
CREATE INDEX ON :Person(name)
조회: CALL db.indexes
삭제: DROP INDEX ON :Label(prop1, …, propN)
DROP INDEX ON :Person(name)
// 레이블이 Person인 노드에 name 값을 UNIQUE한 값으로..
CREATE CONSTRAINT ON (ee:Person) ASSERT ee.name IS UNIQUE
조회: CALL db.constraints
삭제
DROP CONSTRAINT ON (ee:Person) ASSERT ee.name IS UNIQUE