Skip to content

Commit

Permalink
Add example of multiple record type creation (#416)
Browse files Browse the repository at this point in the history
Co-authored-by: Obinna Ekwuno <[email protected]>
  • Loading branch information
Dhghomon and Ekwuno authored Mar 19, 2024
1 parent 3f47673 commit 7fe98ed
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,48 @@ CREATE person:100 CONTENT {
};
```

## Clauses and Options
## Options and clauses

### Creating multiple records

Multiple records or even multiple record types can be created by separating record names by commas.

```surql
--Note: meta::tb(id) returns just the table name portion of a record ID
CREATE townsperson, cat, dog SET
created_at = time::now(),
name = "Just a " + meta::tb(id);
```

```bash title="Output"
[
{
"created_at": "2024-03-19T03:12:05.079Z",
"id": "townsperson:p37ha2lngckp3v8tvf2j",
"name": "Just a townsperson"
},
{
"created_at": "2024-03-19T03:12:05.080Z",
"id": "cat:p1pwbjaq96nhhnuohjtc",
"name": "Just a cat"
},
{
"created_at": "2024-03-19T03:12:05.080Z",
"id": "dog:01vcxgdpuctdk354hzkp",
"name": "Just a dog"
}
]
```

### ONLY

Using the `ONLY` clause after `CREATE` will return just the record object instead of the default, which returns the object inside of an array.

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

### Return Values

By default, the create statement returns the record once the changes have been made. To change what is returned, we can use the `RETURN` clause, specifying either `NONE`, `BEFORE`, `AFTER`, `DIFF`, or a comma-separated list of specific fields to return.
Expand Down

0 comments on commit 7fe98ed

Please sign in to comment.