Skip to content

Commit

Permalink
Add basic create-statement (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ce11an authored Feb 11, 2025
1 parent 157fa5c commit 796f35e
Show file tree
Hide file tree
Showing 7 changed files with 61,455 additions and 58,573 deletions.
32 changes: 32 additions & 0 deletions examples/create.surql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- Create a new record
CREATE person;

-- To specify a specific ID for a table instead, use : followed by a value.
CREATE person:one;

-- Use the type::thing() function to provide a record's table and id separately
CREATE type::thing("person", "one");

-- Create a new record with a text id
CREATE person:tobie SET
name = 'Tobie',
company = 'SurrealDB',
skills = ['Rust', 'Go', 'JavaScript'];

-- Multiple records or even multiple record types can be created by separating table names by commas.
CREATE townsperson, cat, dog SET
created_at = time::now(),
name = "Just a " + meta::tb(id);

-- Returns just a single record
CREATE ONLY person:tobie SET
name = 'Tobie',
company = 'SurrealDB',
skills = ['Rust', 'Go', 'JavaScript'];

-- Return Diff
CREATE person SET age = 46, username = "john-smith" RETURN DIFF;

-- Specify a timeout
CREATE person:john SET age = 46, username = "john-smith" TIMEOUT 500ms;

8 changes: 2 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,9 @@ module.exports = grammar({
$.keyword_create,
optional($.keyword_only),
$.create_target,
optional(choice($.content_clause, $.set_clause, $.unset_clause)),
optional(choice($.content_clause, $.set_clause)),
optional($.return_clause),
optional($.timeout_clause),
optional($.parallel_clause),
),

update_statement: $ =>
Expand All @@ -534,7 +533,6 @@ module.exports = grammar({
$.merge_clause,
$.patch_clause,
$.set_clause,
$.unset_clause,
),
),
optional($.where_clause),
Expand Down Expand Up @@ -883,14 +881,12 @@ module.exports = grammar({
if_exists_clause: $ => seq($.keyword_if, $.keyword_exists),

create_target: $ =>
choice($.identifier, $.variable_name, $.function_call, $.record_id),
choice(commaSeparated($.identifier), $.variable_name, $.function_call, $.record_id),

content_clause: $ => seq($.keyword_content, $.object),

set_clause: $ => seq($.keyword_set, commaSeparated($.field_assignment)),

unset_clause: $ => seq($.keyword_unset, commaSeparated($.field_assignment)),

return_clause: $ =>
seq(
$.keyword_return,
Expand Down
1 change: 0 additions & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
(keyword_on_duplicate_key_update)
(keyword_count)
(keyword_set)
(keyword_unset)
(keyword_return)
(keyword_overwrite)
(keyword_throw)
Expand Down
79 changes: 23 additions & 56 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 1 addition & 36 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 796f35e

Please sign in to comment.