Skip to content

Commit

Permalink
Make .* more prominent than [*] (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhghomon authored Dec 12, 2024
1 parent 83cb6c8 commit f113bcd
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/content/doc-surrealql/datamodel/idioms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ SELECT results[0].score FROM student;
```surql title="Response"
[
{
"results": [
{ "score": 76 }
results: [
{ score: 76 }
]
}
]
Expand All @@ -144,10 +144,10 @@ Here, `results[0].score` accesses the score of the first student in the `results

### All Elements

To access all elements in an array or all fields in an object, use `[*]` or `.*`. This is useful when you want to access all the elements in an array or all the fields in an object.
To access all elements in an array or all fields in an object, use `.*`. This is useful when you want to access all the elements in an array or all the fields in an object.

```surql
SELECT results[*].score FROM student;
```surql
SELECT results.* FROM student;
```

```surql title="Response"
Expand All @@ -167,6 +167,28 @@ SELECT results[*].score FROM student;

This idiom selects all elements in the `score` array.

The operator `[*]` can also be used as an alias of `.*`, and is often seen in definitions and error messages.

```surql
DEFINE FIELD friends ON TABLE person TYPE array<record<person>>;
INFO FOR TABLE person;
```

The output for `INFO FOR TABLE person` includes an automatically generated definition for `friends[*]`, namely every item inside the `friends` field.

```surql
{
events: {},
fields: {
friends: 'DEFINE FIELD friends ON person TYPE array<record<person>> PERMISSIONS FULL',
"friends[*]": 'DEFINE FIELD friends[*] ON person TYPE record<person> PERMISSIONS FULL'
},
indexes: {},
lives: {},
tables: {}
}
```

#### Using `.*` to return values

<Since v="v2.1.0" />
Expand Down

0 comments on commit f113bcd

Please sign in to comment.