SurrealDB for Neo4j developers
Quickly learn how to map your Neo4j knowledge to corresponding SurrealDB concepts and syntax.
Introduction
As a multi-model database, SurrealDB offers a lot of flexibility. Our SQL-like query language SurrealQL is a good example of this, where we often have more than one way to achieve the same result, depending on developer preference. In this mapping guide, we will focus on the syntax that most closely resembles the Cypher query language.
Concepts mapping
For more in-depth explanations of SurrealDB concepts, see the concepts page.
Neo4j | SurrealDB | ||
---|---|---|---|
database | database | ||
node label | table | ||
node | record | ||
node property | field | ||
index | index | ||
id | record id | ||
transactions | transactions | ||
relationships | record links, embedding and graph relations |
Syntax mapping
Let's get you up to speed with SurrealQL syntax with some CRUD examples.
Create
As Neo4j is schemafull, only the SurrealQL schemafull approach is shown below. For a schemafull option see the define table page.
For more SurrealQL examples, see the create, insert and relate pages.
Cypher | SurrealQL | ||
---|---|---|---|
CREATE (John:Person name:'John'), (Jane:Person name: 'Jane') | INSERT INTO person [ id: "John", name: "John", id: "Jane", name: "Jane" ] Table implicitly created if it doesn't exist | ||
MATCH (p:Person name:'Jane'), (pr:Product name:'iPhone') CREATE (p)-[:ORDER]->(pr) | RELATE person:Jane -> order -> product:iPhone There are many differences between how SurrealDB and Neo4j do graph relations. Check out the relate docs for more. | ||
CREATE INDEX personNameIndex FOR (p:Person) ON (p.name) | DEFINE INDEX idx_name ON TABLE person COLUMNS name |
Read
For more SurrealQL examples, see the select, live select and return pages.
Cypher | SurrealQL | ||
---|---|---|---|
MATCH (p:Person) RETURN p | SELECT * FROM person | ||
MATCH (p:Person) RETURN p.name | SELECT name FROM person | ||
MATCH (p:Person) WHERE p.name = "Jane" RETURN p.name | SELECT name FROM person WHERE name = "Jane" | ||
EXPLAIN MATCH (p:Person) WHERE p.name = "Jane" RETURN p.name | SELECT name FROM person WHERE name = "Jane" EXPLAIN | ||
EXPLAIN MATCH (p:Person) WHERE p.name = "Jane" RETURN p.name | SELECT name FROM person WHERE name = "Jane" EXPLAIN | ||
MATCH (p:Person) RETURN count(*) as person_count | SELECT count() AS person_count FROM person GROUP ALL | ||
MATCH (p:Person) RETURN distinct p.name | SELECT array::distinct(name) FROM person GROUP ALL | ||
MATCH (p:Person) RETURN p LIMIT 10 | SELECT * FROM person LIMIT 10 | ||
MATCH (p:Person)-[:ORDER]->(pr:Product) RETURN p.name, pr.name | SELECT name, ->order->product.name FROM person |
Update
For more SurrealQL examples, see the update page.
Cypher | SurrealQL | ||
---|---|---|---|
MATCH (p:Person) WHERE p.name = "Jane" SET p.last_name = 'Doe' RETURN p | UPDATE person SET last_name = "Doe" WHERE name = "Jane" | ||
MATCH (p:Person) WHERE p.name = "Jane" REMOVE p.last_name RETURN p | UPDATE person UNSET last_name WHERE name = "Jane" | ||
MATCH (p:Person) WHERE p.name = "Jane" RETURN p.name | SELECT name FROM person WHERE name = "Jane" |
Delete
For more SurrealQL examples, see the delete and remove pages.
Cypher | SurrealQL | ||
---|---|---|---|
MATCH (p:Person) WHERE p.name = "Jane" DELETE p | DELETE person WHERE name = "Jane" | ||
MATCH (p:Person) DELETE p | DELETE person Node/Table still exists here but is empty | ||
MATCH (p:Person) DELETE p | REMOVE TABLE person Node/Table no longer exists |