Skip to content

Commit d1dcb91

Browse files
committed
Settling on naming convention, fleshing out .db chapter.
1 parent 3f7dee4 commit d1dcb91

File tree

3 files changed

+53
-33
lines changed

3 files changed

+53
-33
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: D1 database
3+
pcx_content_type: concept
4+
sidebar:
5+
order: 1
6+
---
7+
8+
import { Type, MetaInfo, Details } from "~/components";
9+
10+
## Description
11+
12+
You can execute queries on your D1 database through SQL statements.
13+
14+
## Methods
15+
16+
### db.prepare()
17+
18+
D1 API supports both prepared and static statements. 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.
19+
20+
Example of a prepared statement:
21+
22+
```js
23+
const stmt = db.prepare("SELECT * FROM users WHERE name = ?1").bind(someVariable);
24+
// someVariable will replace the placeholder '?1' in the query.
25+
```
26+
27+
Example of a static statement:
28+
29+
```js
30+
const stmt = db.prepare('SELECT * FROM users WHERE name = "John Doe"');
31+
// "John Doe" is hard-coded into the query. This is a static statement.
32+
```
33+
34+
#### Parameters
35+
36+
- <code>sqlQuery</code>: <Type text="String"/> <MetaInfo text="Required"/>
37+
- The SQL query you wish to execute on the database.
38+
39+
#### Return values
40+
41+
- <code>queryResult</code>:
42+
- The result of the SQL query.
43+
44+
### db.batch()
45+
46+
47+
48+
#### Parameters
49+
50+
#### Return values
51+

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/content/docs/d1/worker-api/handle-query-results.mdx renamed to src/content/docs/d1/worker-api/query.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Handle query results
2+
title: D1 Query
33
pcx_content_type: concept
44
sidebar:
55
order: 2
@@ -9,7 +9,7 @@ import { Type, MetaInfo, Details } from "~/components";
99

1010
## Description
1111

12-
You can manipulate the query results which has been obtained after executing a `.db()` method.
12+
You can modify the query results which has been obtained after executing a `.db()` method.
1313

1414
## Methods
1515

0 commit comments

Comments
 (0)