Skip to content

Commit 82a3cf6

Browse files
committed
Adding an example in-situ for convenience for readers.
1 parent 3728197 commit 82a3cf6

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,28 @@ const stmt = env.DB.prepare("SELECT * FROM Customers WHERE CompanyName = ?").bin
3636
#### Return values
3737

3838
- <code>D1PreparedStatement</code>: <Type text="Object"/>
39-
- An object which only contains methods. The methods are: [`bind`](/d1/worker-api/prepared-statements/#bind), [`run`](/d1/worker-api/prepared-statements/#run), [`raw`](/d1/worker-api/prepared-statements/#raw), and [`first`](/d1/worker-api/prepared-statements/#first).
39+
- An object which only contains methods. Refer to [Prepared statement methods](/d1/worker-api/prepared-statements/).
4040

4141
#### Guidance
4242

43-
- Preparing a query statement typically involves using the `bind` method to dynamically bind any required parameters into the statement. Refer to the [`bind` method documentation](/d1/worker-api/prepared-statements/#bind).
43+
You can use the `bind` method to dynamically bind a value into the query statement, as shown below.
44+
45+
- Example of a static statement without using `bind`:
46+
47+
```js
48+
const stmt = db
49+
.prepare("SELECT * FROM Customers WHERE CompanyName = Alfreds Futterkiste AND CustomerId = 1")
50+
```
51+
52+
- Example of an ordered statement using `bind`:
53+
54+
```js
55+
const stmt = db
56+
.prepare("SELECT * FROM Customers WHERE CompanyName = ? AND CustomerId = ?")
57+
.bind("Alfreds Futterkiste", 1);
58+
```
59+
60+
Refer to the [`bind` method documentation](/d1/worker-api/prepared-statements/#bind) for more information.
4461

4562
### `batch()`
4663

0 commit comments

Comments
 (0)