You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Usage and product changes
We improve multi-line query support to allow copy-pasting queries and
scripts containing empty newlines. In particular this makes pasting
entire schema definitions from files.
For example, pasting a console script opening a transaction, defining a
schema containing newlines, and committing, is now possible:
```
>> transaction schema test
define
entity person; # newlines are allowed in pasted scripts:
attribute name, value string;
person owns name;
commit
```
Empty newlines when written _interactively_ still cause queries to be
submitted. However, an explicit query `end;` clause is a valid
alternative now:
```
>> transaction schema test
define
entity person; # newlines are allowed in pasted scripts:
attribute name, value string;
person owns name;
end; # <--- will submit immediately
```
Pasted query pipelines may now be ambiguous, such as the following
example which by defaults executs a single "match-insert" query, even
though there are newlines:
```
> transaction schema test
match $x isa person;
insert $y isa person;
commit
```
To make this a "match" query and a separate "insert" query, we must use
the `end;` markers:
```
> transaction schema test
match $x isa person;
end;
insert $y isa person;
end;
commit
```
**Note that now `end` is a reserved keyword and cannot be used as a
type!**
## Implementation
Queries are now parsed using TypeQL when given input. A "maximum" query
is parsed from the input at a time, so multi-query copy-paste and
scripts need to take care to be include the right terminators between
queries (eg "end;").
Copy file name to clipboardExpand all lines: README.md
+30-3Lines changed: 30 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -96,7 +96,7 @@ will also be autocompleted, while others, such as queries, will not.
96
96
97
97
### Transaction-level commands
98
98
99
-
-`<query>` : Once you're in the transaction REPL, the terminal immediately accepts a multi-line TypeQL query, and will execute it when you **hit enter twice**.
99
+
-`<query>` : Once you're in the transaction REPL, the terminal immediately accepts a multi-line TypeQL query, and will execute it when you **hit enter twice (submit an empty newline) or use an explicit "end;" stage**.
100
100
```
101
101
my-typedb-database::schema>> define
102
102
attribute name, value string;
@@ -105,7 +105,7 @@ will also be autocompleted, while others, such as queries, will not.
105
105
Finished schema query.
106
106
>>
107
107
```
108
-
-`source <file>` : Run TypeQL queries in a file (_not a general console script_), which you can refer to using relative or absolute path. Queries must be terminated by an empty newline.
108
+
-`source <file>` : Run TypeQL queries in a file (_not a general console script_), which you can refer to using relative or absolute path. Queries must be terminated by an empty newline or an explicit "end;" stage.
109
109
```
110
110
my-typedb-database::schema> source ./schema.tql
111
111
Successfully executed 1 queries.
@@ -183,6 +183,31 @@ Finished. Total answers: 1
183
183
Transaction closed
184
184
```
185
185
186
+
Queries will be parsed maximally and newlines **are** allowed.
187
+
If you wish to split a query pipeline into two queries, or skip the usual empty newline after a query,
188
+
use the query "end;" marker:
189
+
```
190
+
>> database create test
191
+
transaction schema test
192
+
define
193
+
entity person; # newlines are allowed in pasted scripts:
194
+
195
+
attribute name, value string;
196
+
197
+
person owns name;
198
+
199
+
commit
200
+
transaction write test
201
+
insert
202
+
$x isa person;
203
+
204
+
$x has name "bob";
205
+
end; # this is required to avoid creating a single "insert-match" query pipeline!
206
+
207
+
match $x isa person, has name "bob"; # this is treated as a new query
208
+
209
+
commit
210
+
```
186
211
187
212
### Non-interactive modes
188
213
@@ -191,7 +216,9 @@ Transaction closed
191
216
We can define a script file that contains the list of commands to run, then invoke console with `./typedb console --script=<path>`.
192
217
193
218
Script files take exactly the same format as scripts pasted directly in the REPL.
194
-
Importantly, this means that the **end of a query is delimited by an empty newline**.
219
+
Importantly, this means that:
220
+
-**Ambiguous query pipelines may need to be split explicitly up with an "end;" marker**.
221
+
-**A query is that is not ended with the "end;" marker must still be terminated with an empty newline**
0 commit comments