Skip to content

Commit d5f8014

Browse files
Dhghomonkearfy
andauthored
Prepare doc tests (#1453)
Co-authored-by: Micha de Vries <[email protected]>
1 parent 05588a3 commit d5f8014

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+10562
-1025
lines changed

bun.lockb

6.55 KB
Binary file not shown.

src/content/doc-surrealql/clauses/explain.mdx

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ Using the `EXPLAIN` clause in addition to the `FULL` keyword is expeciallly usef
2424
For example, consider the performance of the following query when the field `email` is not indexed. We can see that the execution plan will iterate over the whole table.
2525

2626
```surql title="Index not used"
27+
/**[test]
28+
29+
[[test.results]]
30+
value = "[{ address: '1 Bagshot Row', email: '[email protected]', id: person:tobie, name: 'Tobie' }]"
31+
32+
[[test.results]]
33+
value = "[{ detail: { direction: 'forward', table: 'person' }, operation: 'Iterate Table' }, { detail: { type: 'Memory' }, operation: 'Collector' }]"
34+
35+
[[test.results]]
36+
value = "[{ detail: { direction: 'forward', table: 'person' }, operation: 'Iterate Table' }, { detail: { type: 'Memory' }, operation: 'Collector' }, { detail: { type: 'KeysAndValues' }, operation: 'RecordStrategy' }, { detail: { count: 1 }, operation: 'Fetch' }]"
37+
38+
*/
39+
2740
CREATE person:tobie SET
2841
name = "Tobie",
2942
address = "1 Bagshot Row",
@@ -39,6 +52,7 @@ SELECT * FROM person WHERE email='[email protected]' EXPLAIN FULL;
3952
[
4053
{
4154
detail: {
55+
direction: 'forward',
4256
table: 'person'
4357
},
4458
operation: 'Iterate Table'
@@ -56,6 +70,7 @@ SELECT * FROM person WHERE email='[email protected]' EXPLAIN FULL;
5670
[
5771
{
5872
detail: {
73+
direction: 'forward',
5974
table: 'person'
6075
},
6176
operation: 'Iterate Table'
@@ -66,19 +81,40 @@ SELECT * FROM person WHERE email='[email protected]' EXPLAIN FULL;
6681
},
6782
operation: 'Collector'
6883
},
84+
{
85+
detail: {
86+
type: 'KeysAndValues'
87+
},
88+
operation: 'RecordStrategy'
89+
},
6990
{
7091
detail: {
7192
count: 1
7293
},
7394
operation: 'Fetch'
7495
}
7596
]
76-
7797
```
7898

7999
On the other hand, here is the result when the field `email` is indexed. We can see that the execution plan will use the index to retrieve the record.
80100

81101
```surql title="Index used"
102+
/**[test]
103+
104+
[[test.results]]
105+
value = "NONE"
106+
107+
[[test.results]]
108+
value = "[{ address: '1 Bagshot Row', email: '[email protected]', id: person:tobie, name: 'Tobie' }]"
109+
110+
[[test.results]]
111+
value = "[{ detail: { plan: { index: 'fast_email', operator: '=', value: '[email protected]' }, table: 'person' }, operation: 'Iterate Index' }, { detail: { type: 'Memory' }, operation: 'Collector' }]"
112+
113+
[[test.results]]
114+
value = "[{ detail: { plan: { index: 'fast_email', operator: '=', value: '[email protected]' }, table: 'person' }, operation: 'Iterate Index' }, { detail: { type: 'Memory' }, operation: 'Collector' }, { detail: { type: 'KeysAndValues' }, operation: 'RecordStrategy' }, { detail: { count: 1 }, operation: 'Fetch' }]"
115+
116+
*/
117+
82118
DEFINE INDEX fast_email ON TABLE person FIELDS email;
83119
84120
CREATE person:tobie SET
@@ -133,12 +169,17 @@ SELECT * FROM person WHERE email='[email protected]' EXPLAIN FULL;
133169
},
134170
operation: 'Collector'
135171
},
172+
{
173+
detail: {
174+
type: 'KeysAndValues'
175+
},
176+
operation: 'RecordStrategy'
177+
},
136178
{
137179
detail: {
138180
count: 1
139181
},
140182
operation: 'Fetch'
141183
}
142184
]
143-
144185
```

src/content/doc-surrealql/clauses/from.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ This keyword can be particularly useful with SDKs as it can guaranteed to have j
6464

6565
```surql title="Using the ONLY keyword"
6666
-- Select only the 'user' table.
67-
SELECT * FROM ONLY user:one ;
67+
SELECT * FROM ONLY user:one;
6868
6969
-- Selects only the first 10 records from the 'user' table.
7070
SELECT * FROM ONLY user LIMIT 10;

src/content/doc-surrealql/clauses/limit.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ SELECT * FROM person LIMIT 10 START 50;
2929
```
3030

3131
```surql
32+
/**[test]
33+
34+
[[test.results]]
35+
value = "[5, 6, 7, 8, 9]"
36+
37+
*/
38+
3239
-- Select the first 5 records from the array
33-
SELECT * FROM [1,2,3,4,5,6,7,8,9,10] LIMIT 5 START 4;
40+
SELECT * FROM [1,2,3,4,5,6,7,8,9,10] LIMIT 5 START 4;
3441
```
3542

3643
```surql title="Result"

src/content/doc-surrealql/clauses/omit.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ OMIT @fields FROM @table
1818
## Examples
1919

2020
```surql
21+
/**[test]
22+
23+
[[test.results]]
24+
value = "[{ id: person:tobie, name: 'Tobie', opts: { enabled: true, security: 'secure' }, password: '123456' }]"
25+
26+
[[test.results]]
27+
value = "[{ id: person:jaime, name: 'Jaime', opts: { enabled: false, security: 'secure' }, password: 'asdfgh' }]"
28+
29+
[[test.results]]
30+
value = "[{ id: person:jaime, name: 'Jaime', opts: { enabled: false, security: 'secure' }, password: 'asdfgh' }, { id: person:tobie, name: 'Tobie', opts: { enabled: true, security: 'secure' }, password: '123456' }]"
31+
32+
[[test.results]]
33+
value = "[{ id: person:jaime, name: 'Jaime', opts: { enabled: false } }, { id: person:tobie, name: 'Tobie', opts: { enabled: true } }]"
34+
35+
[[test.results]]
36+
value = "[{ id: person:jaime, name: 'Jaime', opts: { } }, { id: person:tobie, name: 'Tobie', opts: { } }]"
37+
38+
*/
39+
2140
CREATE person:tobie SET
2241
name = 'Tobie',
2342
password = '123456',

src/content/doc-surrealql/clauses/split.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ Suppose you have a user table with a field emails that contains an array of emai
2020
Here's how you can use the SPLIT clause in SurrealQL:
2121

2222
```surql
23+
/**[test]
24+
25+
[[test.results]]
26+
value = "[{ emails: ['[email protected]', '[email protected]'], id: user:jhjsg6c9ta32gdut36b8, name: 'John Doe' }]"
27+
skip-record-id-key = true
28+
29+
[[test.results]]
30+
value = "[{ emails: '[email protected]', id: user:jhjsg6c9ta32gdut36b8, name: 'John Doe' }, { emails: '[email protected]', id: user:jhjsg6c9ta32gdut36b8, name: 'John Doe' }]"
31+
skip-record-id-key = true
32+
33+
*/
2334
CREATE user SET
2435
name = "John Doe",
2536
@@ -55,6 +66,31 @@ The output of the query will be:
5566
One practical use case with `SPLIT` is returning every possible combination of the relations inside multiple graph paths. For instance, take the following data below that represents the relations between Canada the country, its provinces, and their cities.
5667

5768
```surql
69+
/**[test]
70+
71+
[[test.results]]
72+
value = "[{ id: country:canada }]"
73+
74+
[[test.results]]
75+
value = "[{ id: province:bc }, { id: province:alberta }]"
76+
77+
[[test.results]]
78+
value = "[{ id: city:vancouver }, { id: city:victoria }, { id: city:edmonton }, { id: city:calgary }]"
79+
80+
[[test.results]]
81+
value = "[{ id: in:5bgf21urlmudhbv87weh, in: city:vancouver, out: province:bc }, { id: in:nt3jd2nxdf28t1eeg7uz, in: city:victoria, out: province:bc }]"
82+
skip-record-id-key = true
83+
84+
[[test.results]]
85+
value = "[{ id: in:6iqjlca9vrnrcotwfb0a, in: city:edmonton, out: province:alberta }, { id: in:56xr5okh0jbmd5d34r0a, in: city:calgary, out: province:alberta }]"
86+
skip-record-id-key = true
87+
88+
[[test.results]]
89+
value = "[{ id: in:gr88pyx3de7nrsm63uo2, in: province:bc, out: country:canada }, { id: in:fidjczbmblc01syn4gzd, in: province:alberta, out: country:canada }]"
90+
skip-record-id-key = true
91+
92+
*/
93+
5894
CREATE country:canada;
5995
CREATE province:bc, province:alberta;
6096
CREATE city:vancouver, city:victoria, city:edmonton, city:calgary;

src/content/doc-surrealql/clauses/where.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ UPDATE [TABLE_NAME] SET [FIELDS] WHERE [CONDITION] = [VALUE];
4141
## Setting conditions in `DEFINE FUNCTION` statements
4242

4343
```surql
44+
/**[test]
45+
46+
[[test.results]]
47+
value = "NONE"
48+
49+
*/
4450
-- Define a function that checks if a relation exists between two nodes
4551
DEFINE FUNCTION fn::relation_exists(
4652
$in: record,
@@ -59,6 +65,12 @@ DEFINE FUNCTION fn::relation_exists(
5965
The `WHERE` clause can be used to specify the conditions for the permissions of a table and based on the conditions, the permissions are applied to the table CRUD operations.
6066

6167
```surql
68+
/**[test]
69+
70+
[[test.results]]
71+
value = "NONE"
72+
73+
*/
6274
-- Specify access permissions for the 'post' table
6375
DEFINE TABLE post SCHEMALESS
6476
PERMISSIONS
@@ -79,6 +91,13 @@ DEFINE TABLE post SCHEMALESS
7991
```
8092

8193
```surql
94+
/**[test]
95+
96+
[[test.results]]
97+
value = "NONE"
98+
99+
*/
100+
82101
-- Define a relation table, and constrain the type of relation which can be stored
83102
DEFINE TABLE assigned_to SCHEMAFULL TYPE RELATION IN tag OUT sticky
84103
PERMISSIONS

0 commit comments

Comments
 (0)