You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/changelogs/d1.yaml
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ entries:
19
19
- publish_date: "2024-07-26"
20
20
title: Fixed bug in TypeScript typings for run() API
21
21
description: |-
22
-
The `run()` method as part of the [D1 Client API](/d1/build-with-d1/d1-client-api/) had an incorrect (outdated) type definition, which has now been addressed as of [`@cloudflare/workers-types`](https://www.npmjs.com/package/@cloudflare/workers-types) version `4.20240725.0`.
22
+
The `run()` method as part of the [D1 Client API](/d1/worker-api/) had an incorrect (outdated) type definition, which has now been addressed as of [`@cloudflare/workers-types`](https://www.npmjs.com/package/@cloudflare/workers-types) version `4.20240725.0`.
23
23
24
24
The correct type definition is `stmt.run<T>(): D1Result`, as `run()` returns the result rows of the query. The previously _incorrect_ type definition was `stmt.run(): D1Response`, which only returns query metadata and no results.
25
25
@@ -28,7 +28,7 @@ entries:
28
28
description: |-
29
29
Previously, D1's [HTTP API](/api/operations/cloudflare-d1-query-database) returned a HTTP `500 Internal Server` error for queries that came in while a D1 database was overloaded. These requests now correctly return a `HTTP 429 Too Many Requests` error.
30
30
31
-
D1's [Workers API](/d1/build-with-d1/d1-client-api/) is unaffected by this change.
31
+
D1's [Workers API](/d1/worker-api/) is unaffected by this change.
32
32
33
33
- publish_date: "2024-04-30"
34
34
title: D1 alpha databases will stop accepting live SQL queries on August 15, 2024
@@ -42,7 +42,7 @@ entries:
42
42
description: |-
43
43
Previously, D1's [HTTP API](/api/operations/cloudflare-d1-query-database) returned a HTTP `500 Internal Server` error for an invalid query. An invalid SQL query now correctly returns a `HTTP 400 Bad Request` error.
44
44
45
-
D1's [Workers API](/d1/build-with-d1/d1-client-api/) is unaffected by this change.
45
+
D1's [Workers API](/d1/worker-api/) is unaffected by this change.
46
46
47
47
- publish_date: "2024-04-05"
48
48
title: D1 alpha databases are deprecated
@@ -81,24 +81,24 @@ entries:
81
81
- publish_date: "2024-02-16"
82
82
title: API changes to `run()`
83
83
description: |-
84
-
A previous change (made on 2024-02-13) to the `run()` [query statement method](/d1/build-with-d1/d1-client-api/#await-stmtrun) has been reverted.
84
+
A previous change (made on 2024-02-13) to the `run()` [query statement method](/d1/worker-api/prepared-statements/#run) has been reverted.
85
85
86
-
`run()` now returns a `D1Result`, including the result rows, matching its original behaviour prior to the change on 2024-02-13.
86
+
`run()` now returns a `D1Result`, including the result rows, matching its original behavior prior to the change on 2024-02-13.
87
87
88
-
Future change to `run()` to return a [`D1ExecResult`](/d1/build-with-d1/d1-client-api/#return-object), as originally intended and documented, will be gated behind a [compatibility date](/workers/configuration/compatibility-dates/) as to avoid breaking existing Workers relying on the way `run()` currently works.
88
+
Future change to `run()` to return a [`D1ExecResult`](/d1/worker-api/return-object/#d1execresult), as originally intended and documented, will be gated behind a [compatibility date](/workers/configuration/compatibility-dates/) as to avoid breaking existing Workers relying on the way `run()` currently works.
89
89
90
90
- publish_date: "2024-02-13"
91
91
title: API changes to `raw()`, `all()` and `run()`
92
92
description: |-
93
-
D1's `raw()`, `all()` and `run()` [query statement methods](/d1/build-with-d1/d1-client-api/#query-statement-methods) have been updated to reflect their intended behaviour and improve compatibility with ORM libraries.
93
+
D1's `raw()`, `all()` and `run()` [query statement methods](/d1/worker-api/prepared-statements/) have been updated to reflect their intended behavior and improve compatibility with ORM libraries.
94
94
95
95
`raw()` now correctly returns results as an array of arrays, allowing the correct handling of duplicate column names (such as when joining tables), as compared to `all()`, which is unchanged and returns an array of objects. To include an array of column names in the results when using `raw()`, use `raw({columnNames: true})`.
96
96
97
-
`run()` no longer incorrectly returns a `D1Result` and instead returns a [`D1ExecResult`](/d1/build-with-d1/d1-client-api/#return-object) as originally intended and documented.
97
+
`run()` no longer incorrectly returns a `D1Result` and instead returns a [`D1ExecResult`](/d1/worker-api/return-object/#d1execresult) as originally intended and documented.
98
98
99
99
This may be a breaking change for some applications that expected `raw()` to return an array of objects.
100
100
101
-
Refer to [D1 client API](/d1/build-with-d1/d1-client-api/) to review D1's query methods, return types and TypeScript support in detail.
101
+
Refer to [D1 client API](/d1/worker-api/) to review D1's query methods, return types and TypeScript support in detail.
102
102
103
103
- publish_date: "2024-01-18"
104
104
title: Support for LIMIT on UPDATE and DELETE statements
@@ -140,7 +140,7 @@ entries:
140
140
description: |-
141
141
D1 now returns a count of `rows_written` and `rows_read` for every query executed, allowing you to assess the cost of query for both [pricing](/d1/platform/pricing/) and [index optimization](/d1/build-with-d1/use-indexes/) purposes.
142
142
143
-
The `meta` object returned in [D1's Client API](/d1/build-with-d1/d1-client-api/) contains a total count of the rows read (`rows_read`) and rows written (`rows_written`) by that query. For example, a query that performs a full table scan (for example, `SELECT * FROM users`) from a table with 5000 rows would return a `rows_read` value of `5000`:
143
+
The `meta` object returned in [D1's Client API](/d1/worker-api/return-object/#d1result) contains a total count of the rows read (`rows_read`) and rows written (`rows_written`) by that query. For example, a query that performs a full table scan (for example, `SELECT * FROM users`) from a table with 5000 rows would return a `rows_read` value of `5000`:
144
144
```json
145
145
"meta": {
146
146
"duration": 0.20472300052642825,
@@ -200,7 +200,7 @@ entries:
200
200
- publish_date: "2023-06-12"
201
201
title: Deprecating Error.cause
202
202
description: |-
203
-
As of [`wrangler v3.1.1`](https://github.com/cloudflare/workers-sdk/releases/tag/wrangler%403.1.1) the [D1 client API](/d1/build-with-d1/d1-client-api/) now returns [detailed error messages](/d1/build-with-d1/d1-client-api/#errors) within the top-level `Error.message` property, and no longer requires developers to inspect the `Error.cause.message` property.
203
+
As of [`wrangler v3.1.1`](https://github.com/cloudflare/workers-sdk/releases/tag/wrangler%403.1.1) the [D1 client API](/d1/worker-api/) now returns [detailed error messages](/d1/observability/debug-d1/) within the top-level `Error.message` property, and no longer requires developers to inspect the `Error.cause.message` property.
204
204
205
205
To facilitate a transition from the previous `Error.cause` behaviour, detailed error messages will continue to be populated within `Error.cause` as well as the top-level `Error` object until approximately July 14th, 2023. Future versions of both `wrangler` and the D1 client API will no longer populate `Error.cause` after this date.
Copy file name to clipboardExpand all lines: src/content/docs/d1/build-with-d1/foreign-keys.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ By default, D1 enforces that foreign key constraints are valid within all querie
16
16
17
17
## Defer foreign key constraints
18
18
19
-
When running a [query](/d1/build-with-d1/d1-client-api/), [migration](/d1/reference/migrations/) or [importing data](/d1/build-with-d1/import-export-data/) against a D1 database, there may be situations in which you need to disable foreign key validation during table creation or changes to your schema.
19
+
When running a [query](/d1/worker-api/), [migration](/d1/reference/migrations/) or [importing data](/d1/build-with-d1/import-export-data/) against a D1 database, there may be situations in which you need to disable foreign key validation during table creation or changes to your schema.
20
20
21
21
D1's foreign key enforcement is equivalent to SQLite's `PRAGMA foreign_keys = on` directive. Because D1 runs every query inside an implicit transaction, user queries cannot change this during a query or migration.
22
22
@@ -87,7 +87,7 @@ There are five actions you can set when defining the `ON UPDATE` and/or `ON DELE
87
87
88
88
:::caution[CASCADE usage]
89
89
90
-
Although `CASCADE` can be the desired behavior in some cases, deleting child rows across tables can have undesirable effects and/or result in unintended side effects for your users.
90
+
Although `CASCADE` can be the desired behavior in some cases, deleting child rows across tables can have undesirable effects and/or result in unintended side effects for your users.
91
91
:::
92
92
93
93
In the following example, deleting a user from the `users` table will delete all related rows in the `scores` table as you have defined `ON DELETE CASCADE`. Delete all related rows in the `scores` table if you do not want to retain the scores for any users you have deleted entirely. This might mean that *other* users can no longer look up or refer to scores that were still valid.
@@ -110,5 +110,5 @@ CREATE TABLE scores (
110
110
## Next Steps
111
111
112
112
* Read the SQLite [`FOREIGN KEY`](https://www.sqlite.org/foreignkeys.html) documentation.
113
-
* Learn how to [use the D1 client API](/d1/build-with-d1/d1-client-api/) from within a Worker.
113
+
* Learn how to [use the D1 Workers Binding API](/d1/worker-api/) from within a Worker.
114
114
* Understand how [database migrations work](/d1/reference/migrations/) with D1.
Copy file name to clipboardExpand all lines: src/content/docs/d1/build-with-d1/query-json.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ This allows you to more precisely query over data and reduce the result set your
19
19
20
20
## Types
21
21
22
-
JSON data is stored as a `TEXT` column in D1. JSON types follow the same [type conversion rules](/d1/build-with-d1/d1-client-api/#type-conversion) as D1 in general, including:
22
+
JSON data is stored as a `TEXT` column in D1. JSON types follow the same [type conversion rules](/d1/worker-api/#type-conversion) as D1 in general, including:
23
23
24
24
* A JSON null is treated as a D1 `NULL`.
25
25
* A JSON number is treated as an `INTEGER` or `REAL`.
@@ -184,7 +184,7 @@ To replace an existing value, use `json_replace()`, which will overwrite an exis
184
184
Use `json_each` to expand an array into multiple rows. This can be useful when composing a `WHERE column IN (?)` query over several values. For example, if you wanted to update a list of users by their integer `id`, use `json_each` to return a table with each value as a column called `value`:
185
185
186
186
```sql
187
-
UPDATE users
187
+
UPDATE users
188
188
SET last_audited ='2023-05-16T11:24:08+00:00'
189
189
WHERE id IN (SELECT value FROM json_each('[183183, 13913, 94944]'))
You can use `json_each` with D1's [client API](/d1/build-with-d1/d1-client-api/) in a Worker by creating a statement and using `JSON.stringify` to pass an array as a [bound parameter](/d1/build-with-d1/d1-client-api/#parameter-binding):
211
+
You can use `json_each` with [D1 Workers Binding API](/d1/worker-api/) in a Worker by creating a statement and using `JSON.stringify` to pass an array as a [bound parameter](/d1/worker-api/d1-database/#guidance):
Copy file name to clipboardExpand all lines: src/content/docs/d1/examples/d1-and-hono.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Hono is a fast web framework for building API-first applications, and it include
19
19
When using Workers:
20
20
21
21
* Ensure you have configured [`wrangler.toml`](/d1/get-started/#3-bind-your-worker-to-your-d1-database) to bind your D1 database to your Worker.
22
-
* You can access your D1 databases via Hono's [`Context`](https://hono.dev/api/context) parameter: [bindings](https://hono.dev/getting-started/cloudflare-workers#bindings) are exposed on `context.env`. If you configured a [binding](/pages/functions/bindings/#d1-databases) named `DB`, then you would access D1's [client API](/d1/build-with-d1/d1-client-api/#query-statement-methods) methods via `c.env.DB`.
22
+
* You can access your D1 databases via Hono's [`Context`](https://hono.dev/api/context) parameter: [bindings](https://hono.dev/getting-started/cloudflare-workers#bindings) are exposed on `context.env`. If you configured a [binding](/pages/functions/bindings/#d1-databases) named `DB`, then you would access [D1 Workers Binding API](/d1/worker-api/prepared-statements/) methods via `c.env.DB`.
23
23
* Refer to the Hono documentation for [Cloudflare Workers](https://hono.dev/getting-started/cloudflare-workers).
24
24
25
25
If you are using [Pages Functions](/pages/functions/):
Copy file name to clipboardExpand all lines: src/content/docs/d1/examples/d1-and-remix.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ To set up a new Remix site on Cloudflare Pages that can query D1:
25
25
The following example shows you how to define a Remix [`loader`](https://remix.run/docs/en/main/route/loader) that has a binding to a D1 database.
26
26
27
27
* Bindings are passed through on the `context.env` parameter passed to a `LoaderFunction`.
28
-
* If you configured a [binding](/pages/functions/bindings/#d1-databases) named `DB`, then you would access D1's [client API](/d1/build-with-d1/d1-client-api/#query-statement-methods) methods via `context.env.DB`.
28
+
* If you configured a [binding](/pages/functions/bindings/#d1-databases) named `DB`, then you would access [D1 Workers Binding API](/d1/worker-api/prepared-statements/) methods via `context.env.DB`.
Copy file name to clipboardExpand all lines: src/content/docs/d1/get-started.mdx
+3-5Lines changed: 3 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -187,14 +187,12 @@ You create bindings by updating your `wrangler.toml` file.
187
187
188
188
- The value (string) you set for `binding` is the **binding name**, and is used to reference this database in your Worker. In this tutorial, name your binding `DB`.
189
189
- The binding name must be [a valid JavaScript variable name](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#variables). For example, `binding = "MY_DB"` or `binding = "productionDB"` would both be valid names for the binding.
190
-
- Your binding is available in your Worker at `env.<BINDING_NAME>` and the D1 [client API](/d1/build-with-d1/d1-client-api/) is exposed on this binding.
190
+
- Your binding is available in your Worker at `env.<BINDING_NAME>` and the D1 [Workers Binding API](/d1/worker-api/) is exposed on this binding.
191
191
192
192
</Steps>
193
193
194
194
:::note
195
-
196
-
When you execute the `wrangler d1 create` command, the client API package (which implements the D1 API and database class) is automatically installed. For more information on the D1 Client API, refer to [D1 Client API](/d1/build-with-d1/d1-client-api/).
197
-
195
+
When you execute the `wrangler d1 create` command, the client API package (which implements the D1 API and database class) is automatically installed. For more information on the D1 Workers Binding API, refer to [Workers Binding API](/d1/worker-api/).
198
196
:::
199
197
200
198
You can also bind your D1 database to a [Pages Function](/pages/functions/). For more information, refer to [Functions Bindings for D1](/pages/functions/bindings/#d1-databases).
@@ -336,7 +334,7 @@ After you have set up your database, run an SQL query from within your Worker.
336
334
In the code above, you:
337
335
338
336
1. Define a binding to your D1 database in your TypeScript code. This binding matches the `binding` value you set in `wrangler.toml` under `[[d1_databases]]`.
339
-
2. Query your database using `env.DB.prepare` to issue a [prepared query](/d1/build-with-d1/d1-client-api/) with a placeholder (the `?` in the query).
337
+
2. Query your database using `env.DB.prepare` to issue a [prepared query](/d1/worker-api/d1-database/#prepare) with a placeholder (the `?` in the query).
340
338
3. Call `bind()` to safely and securely bind a value to that placeholder. In a real application, you would allow a user to define the `CompanyName` they want to list results for. Using `bind()` prevents users from executing arbitrary SQL (known as "SQL injection") against your application and deleting or otherwise modifying your database.
341
339
4. Execute the query by calling `all()` to return all rows (or none, if the query returns none).
342
340
5. Return your query results, if any, in JSON format with `Response.json(results)`.
Copy file name to clipboardExpand all lines: src/content/docs/d1/index.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Create new serverless SQL databases to query from your Workers and Pages project
25
25
26
26
D1 is Cloudflare’s native serverless database. D1 allows you to build applications that handle large amounts of users at no extra cost. With D1, you can restore your database to any minute within the last 30 days.
27
27
28
-
Create your first D1 database by [following the Get started guide](/d1/get-started/), learn how to [import data into a database](/d1/build-with-d1/import-export-data/), and how to [interact with your database](/d1/build-with-d1/d1-client-api/) directly from [Workers](/workers/) or [Pages](/pages/functions/bindings/#d1-databases).
28
+
Create your first D1 database by [following the Get started guide](/d1/get-started/), learn how to [import data into a database](/d1/build-with-d1/import-export-data/), and how to [interact with your database](/d1/worker-api/) directly from [Workers](/workers/) or [Pages](/pages/functions/bindings/#d1-databases).
29
29
30
30
***
31
31
@@ -38,7 +38,7 @@ Create your first D1 database, establish a schema, import data and query D1 dire
Copy file name to clipboardExpand all lines: src/content/docs/d1/observability/metrics-analytics.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Metrics can be queried (and are retained) for the past 31 days.
27
27
28
28
### Row counts
29
29
30
-
D1 returns the number of rows read, rows written (or both) in response to each individual query via [the client API](/d1/build-with-d1/d1-client-api/#return-object).
30
+
D1 returns the number of rows read, rows written (or both) in response to each individual query via [the Workers Binding API](/d1/worker-api/return-object/).
31
31
32
32
Row counts are a precise count of how many rows were read (scanned) or written by that query.
33
33
Inspect row counts to understand the performance and cost of a given query, including whether you can reduce the rows read [using indexes](/d1/build-with-d1/use-indexes/). Use query counts to understand the total volume of traffic against your databases and to discern which databases are actively in-use.
@@ -142,7 +142,7 @@ query {
142
142
143
143
D1 provides metrics that let you understand and debug query performance. You can access these via GraphQL's `d1QueriesAdaptiveGroups` or `wrangler d1 insights` command.
144
144
145
-
D1 captures your query strings to make it easier to analyze metrics across query executions. [Bound parameters](/d1/build-with-d1/d1-client-api/#parameter-binding) are not captured to remove any sensitive information.
145
+
D1 captures your query strings to make it easier to analyze metrics across query executions. [Bound parameters](/d1/worker-api/prepared-statements/#guidance) are not captured to remove any sensitive information.
0 commit comments