Skip to content

Commit 02e1524

Browse files
committed
Adding that you can pass multiple queries into a single statement.
1 parent 55b2e8b commit 02e1524

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/content/docs/d1/build-with-d1/d1-client-api.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ const stmt = db.prepare('SELECT * FROM users WHERE name = "John Doe"');
2525

2626
You can pass multiple queries through `db.prepare()`.
2727

28+
### Pass multiple queries in a single statement
29+
30+
You can pass multiple queries into a single `.prepare()` statement. Simply delineate each query with a semi-colon.
31+
32+
```js
33+
const stmt = db.prepare("DELETE FROM users WHERE (name, age) = (SELECT name, age FROM users ORDER BY name, age LIMIT 1) ;SELECT * FROM users WHERE name = ?1").bind("Joe")
34+
```
35+
36+
Note the following restrictions when passing multiple queries:
37+
38+
- The statement only returns the results of the last query, even though all queries are executed.
39+
- You can only pass parameters to the last query.
40+
2841
## Parameter binding
2942

3043
D1 follows the [SQLite convention](https://www.sqlite.org/lang_expr.html#varparam) for prepared statements parameter binding. Currently, D1 only supports Ordered (`?NNNN`) and Anonymous (`?`) parameters. In the future, D1 will support named parameters as well.

0 commit comments

Comments
 (0)