Cypher Query Language
Định nghĩa
Cypher Query Language là declarative query language cho Property Graph, dùng vertex-edge pattern để tạo và match graph data.
Cú pháp trực giác
(Idaho:Location {name:'Idaho'})-[:WITHIN]->(USA:Location)- Parentheses biểu diễn vertex.
- Square brackets biểu diễn edge.
- Arrow biểu diễn hướng relationship.
- Label/type đứng sau
:. - Properties nằm trong
{}.
Variable-length traversal
(place)-[:WITHIN*0..]->(country)*0.. nghĩa là theo edge WITHIN zero hoặc nhiều lần. Query không cần biết trước location cách country bao nhiêu tầng.
Tính declarative
Cypher mô tả graph pattern cần match, không ép engine bắt đầu từ vertex nào. Optimizer có thể scan person hoặc dùng index tìm location rồi traversal ngược, miễn trả cùng kết quả.
So với SQL
Graph có thể lưu trong relational tables, nhưng variable-length path thường cần recursive CTE. Cypher làm path trở thành first-class syntax nên cùng intent được biểu đạt ngắn và gần domain hơn.