Skip to content

Commit 6ab8172

Browse files
Apply suggestions from code review
Co-authored-by: Lambros Petrou <[email protected]>
1 parent 5aa097a commit 6ab8172

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/content/docs/d1/worker-api/database.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,22 @@ D1 API supports both prepared and static statements.
4444

4545
The recommended approach is to use prepared statements (which are precompiled objects used by the database) to run the SQL. Prepared statements lead to faster overall execution and prevent SQL injection attacks.
4646

47-
Example of a prepared statement:
47+
Example of a prepared statement with dynamically bound value:
4848

4949
```js
50+
// Dynamically generate the value to use.
51+
const someVariable = "John Doe";
5052
const stmt = db.prepare("SELECT * FROM users WHERE name = ?1").bind(someVariable);
5153
// A variable (someVariable) will replace the placeholder '?1' in the query.
52-
// This is a prepared statement.
54+
// `stmt` is a prepared statement.
5355
```
5456

5557
Example of a static statement:
5658

5759
```js
5860
const stmt = db.prepare('SELECT * FROM users WHERE name = "John Doe"');
5961
// "John Doe" is hard-coded into the query.
60-
// This is a static statement.
62+
// `stmt` will also be a prepared statement.
6163
```
6264

6365
#### Parameters
@@ -74,7 +76,7 @@ const stmt = db.prepare('SELECT * FROM users WHERE name = "John Doe"');
7476

7577
- You can pass multiple queries into a single `.prepare()` statement. Simply delineate each query with a semi-colon.
7678
- The statement only returns the results of the last query, even though all queries are executed.
77-
- You can only pass parameters to the last query.
79+
- You can only bind parameters to the last query.
7880
```js
7981
const stmt = db.prepare(`SELECT * FROM users WHERE name = "Anthony"; SELECT * FROM users WHERE name = ?1`).bind("Joe")
8082
```
@@ -137,7 +139,7 @@ await db.batch([
137139
const rows = await db.batch([
138140
db.prepare("SELECT * FROM users WHERE name = ?1").bind("John"),
139141
db.prepare("SELECT * FROM users WHERE name = ?1").bind("Anthony")
140-
]);
142+
]);
141143
```
142144
```js
143145
console.log(rows[0].results);
@@ -163,7 +165,7 @@ console.log(rows[1].results);
163165
name: "Anthony Hopkins",
164166
age: 66,
165167
},
166-
]
168+
]
167169
```
168170
</Details>
169171

src/content/docs/d1/worker-api/query.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You can modify the query results which has been obtained after executing a `.db(
1515

1616
### `stmt.run()`
1717

18-
Runs the query (or queries) and returns results.
18+
Runs the prepared query (or queries) and returns results.
1919

2020
```js
2121
const { results } = await stmt.run();

0 commit comments

Comments
 (0)