Skip to content

Commit

Permalink
Feat(old-tables-conversion): Adds old tables style conversion (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitrianoudi authored Mar 9, 2024
1 parent 94fbfc6 commit c6a56c6
Show file tree
Hide file tree
Showing 3 changed files with 516 additions and 62 deletions.
2 changes: 1 addition & 1 deletion versioned_docs/version-1.2.x/introduction/mongo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ For more in-depth explanations of SurrealDB concepts, see the [concepts page](/d
reference and embedding
</td>
<td colspan="2" scope="row" data-label="SurrealDB">
record links ,embedding and graph relations
record links, embedding and graph relations
</td>
</tr>
</tbody>
Expand Down
294 changes: 258 additions & 36 deletions versioned_docs/version-1.2.x/introduction/neo4j.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,80 @@ As a multi-model database, SurrealDB offers a lot of flexibility. Our SQL-like q
## Concepts mapping
For more in-depth explanations of SurrealDB concepts, see the [concepts page](/docs/surrealdb/introduction/concepts).

| Neo4j | SurrealDB |
|---------------|---------------------------------------------|
| database | database |
| node label | table |
| node | record |
| node property | field |
| index | index |
| id | record id |
| transaction | transaction |
| relationships | record links, embedding and graph relations |
<table>
<thead>
<tr>
<th colspan="2" scope="col">Neo4j</th>
<th colspan="2" scope="col">SurrealDB</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2" scope="row" data-label="Neo4j">
database
</td>
<td colspan="2" scope="row" data-label="SurrealDB">
database
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="Neo4j">
node label
</td>
<td colspan="2" scope="row" data-label="SurrealDB">
table
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="Neo4j">
node
</td>
<td colspan="2" scope="row" data-label="SurrealDB">
record
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="Neo4j">
node property
</td>
<td colspan="2" scope="row" data-label="SurrealDB">
field
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="Neo4j">
index
</td>
<td colspan="2" scope="row" data-label="SurrealDB">
index
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="Neo4j">
id
</td>
<td colspan="2" scope="row" data-label="SurrealDB">
record id
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="Neo4j">
transactions
</td>
<td colspan="2" scope="row" data-label="SurrealDB">
transactions
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="Neo4j">
relationships
</td>
<td colspan="2" scope="row" data-label="SurrealDB">
record links, embedding and graph relations
</td>
</tr>
</tbody>
</table>

## Syntax mapping
Let's get you up to speed with SurrealQL syntax with some CRUD examples.
Expand All @@ -46,41 +110,199 @@ As Neo4j is schemafull, only the SurrealQL schemafull approach is shown below. F

For more SurrealQL examples, see the [create](/docs/surrealdb/surrealql/statements/create), [insert](/docs/surrealdb/surrealql/statements/insert) and [relate](/docs/surrealdb/surrealql/statements/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 |
<table>
<thead>
<tr>
<th colspan="2" scope="col">Cypher</th>
<th colspan="2" scope="col">SurrealQL</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2" scope="row" data-label="SQL">
CREATE (John:Person {`name:'John'`}), (Jane:Person {`name: 'Jane'`})
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
INSERT INTO person [ {`id: "John", name: "John"`}, {`id: "Jane", name: "Jane"`} ] Table implicitly created if it doesn't exist
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person {`name:'Jane'`}), (pr:Product {`name:'iPhone'`}) CREATE (p)-[:ORDER]->(pr)
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
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.
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
CREATE INDEX personNameIndex FOR (p:Person) ON (p.name)
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
DEFINE INDEX idx_name ON TABLE person COLUMNS name
</td>
</tr>
</tbody>
</table>

### Read
For more SurrealQL examples, see the [select](/docs/surrealdb/surrealql/statements/select), [live select](/docs/surrealdb/surrealql/statements/live-select) and [return](https://surrealdb.com/docs/surrealql/statements/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 |
| 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 |

<table>
<thead>
<tr>
<th colspan="2" scope="col">Cypher</th>
<th colspan="2" scope="col">SurrealQL</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) RETURN p
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
SELECT * FROM person
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) RETURN p.name
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
SELECT name FROM person
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) WHERE p.name = "Jane" RETURN p.name
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
SELECT name FROM person WHERE name = "Jane"
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
EXPLAIN MATCH (p:Person) WHERE p.name = "Jane" RETURN p.name
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
SELECT name FROM person WHERE name = "Jane" EXPLAIN
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
EXPLAIN MATCH (p:Person) WHERE p.name = "Jane" RETURN p.name
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
SELECT name FROM person WHERE name = "Jane" EXPLAIN
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) RETURN count(*) as person_count
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
SELECT count() AS person_count FROM person GROUP ALL
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) RETURN distinct p.name
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
SELECT array::distinct(name) FROM person GROUP ALL
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) RETURN p LIMIT 10
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
SELECT * FROM person LIMIT 10
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person)-[:ORDER]->(pr:Product) RETURN p.name, pr.name
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
SELECT name, ->order->product.name FROM person
</td>
</tr>
</tbody>
</table>

### Update
For more SurrealQL examples, see the [update](/docs/surrealdb/surrealql/statements/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" |
<table>
<thead>
<tr>
<th colspan="2" scope="col">Cypher</th>
<th colspan="2" scope="col">SurrealQL</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) WHERE p.name = "Jane" SET p.last_name = 'Doe' RETURN p
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
UPDATE person SET last_name = "Doe" WHERE name = "Jane"
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) WHERE p.name = "Jane" REMOVE p.last_name RETURN p
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
UPDATE person UNSET last_name WHERE name = "Jane"
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) WHERE p.name = "Jane" RETURN p.name
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
SELECT name FROM person WHERE name = "Jane"
</td>
</tr>
</tbody>
</table>

### Delete
For more SurrealQL examples, see the [delete](/docs/surrealdb/surrealql/statements/delete) and [remove](/docs/surrealdb/surrealql/statements/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 |
<table>
<thead>
<tr>
<th colspan="2" scope="col">Cypher</th>
<th colspan="2" scope="col">SurrealQL</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) WHERE p.name = "Jane" DELETE p
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
DELETE person WHERE name = "Jane"
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) DELETE p
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
DELETE person Node/Table still exists here but is empty
</td>
</tr>
<tr>
<td colspan="2" scope="row" data-label="SQL">
MATCH (p:Person) DELETE p
</td>
<td colspan="2" scope="row" data-label="SurrealQL">
REMOVE TABLE person Node/Table no longer exists
</td>
</tr>
</tbody>
</table>
Loading

0 comments on commit c6a56c6

Please sign in to comment.