Skip to content

Commit f8e0c56

Browse files
authored
Fix Durable Object example of using sql.exec() with a bound param (#20366)
It sure looks to me like the array wrapping here is a mistake, both comparing it to other documentation and to the code that has worked for me in practice.
1 parent af4308a commit f8e0c56

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/content/docs/durable-objects/api/sql-storage.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ This type can then be passed as the type parameter to a `sql.exec` call:
176176
177177
```ts
178178
// The type parameter is passed between the "pointy brackets" before the function argument:
179-
const result = this.ctx.storage.sql.exec<User>("SELECT id, name, email_address, version FROM users WHERE id = ?", [user_id]).one()
179+
const result = this.ctx.storage.sql.exec<User>("SELECT id, name, email_address, version FROM users WHERE id = ?", user_id).one()
180180
// result will now have a type of "User"
181181

182182
// Alternatively, if you are iterating over results using a cursor
183-
let cursor = this.sql.exec<User>("SELECT id, name, email_address, version FROM users WHERE id = ?", [user_id])
183+
let cursor = this.sql.exec<User>("SELECT id, name, email_address, version FROM users WHERE id = ?", user_id)
184184
for (let row of cursor) {
185185
// Each row object will be of type User
186186
}
@@ -194,7 +194,7 @@ type UserRow = [
194194
];
195195

196196
// ... and then pass it as the type argument to the raw() method:
197-
let cursor = sql.exec("SELECT id, name, email_address, version FROM users WHERE id = ?", [user_id]).raw<UserRow>();
197+
let cursor = sql.exec("SELECT id, name, email_address, version FROM users WHERE id = ?", user_id).raw<UserRow>();
198198

199199
for (let row of cursor) {
200200
// row is of type User

0 commit comments

Comments
 (0)