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
* Moving Error section away from "Query D1".
* Redirecting Query D1 to Workers Binding API section.
* Replacing all interlinks to Query D1 chapter, to the new structure.
* Update src/content/docs/d1/worker-api/prepared-statements.mdx
Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com>
* Fixing grammar.
* Moving Wrangler commands out of Reference. Reshuffling chapters.
* Resolving merge conflict, adding global commands once at the bottom.
* Moving "global commands" out of the partial.
* Introducing APIs in Query D1. Introducing Wrangler commands properly.
* Setting up redirects, fixing broken link.
* Adding missing `/`
* Fixing redirects.
* Resolving two conflicting redirects.
* Fixing redirect
* Reordering API pages, moving Remote dev below Local dev.
* Editing chapter contents to action feedback.
* Renaming "Build with D1" to "Best practices".
* Moving foreign keys and query json into SQL API.
* Moving foreign keys and query json into sql api.
* Removing "D1" from REST and Wrangler sidebar.
* Introducing query JSON and foreign keys in Query databases chapter.
* Restructuring "Query database", changing the example of
* Editing Wrangler example. Restructuring to better explain how SQL fits into D1.
---------
Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: src/content/changelogs/d1.yaml
+15-15Lines changed: 15 additions & 15 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
@@ -58,7 +58,7 @@ entries:
58
58
59
59
* Developers with a Workers Paid plan now have a 10GB GB per-database limit (up from 2GB), which can be combined with existing limit of 50,000 databases per account.
60
60
* Developers with a Workers Free plan retain the 500 MB per-database limit and can create up to 10 databases per account.
61
-
* D1 databases can be [exported](/d1/build-with-d1/import-export-data/#export-an-existing-d1-database) as a SQL file.
61
+
* D1 databases can be [exported](/d1/best-practices/import-export-data/#export-an-existing-d1-database) as a SQL file.
62
62
63
63
- publish_date: "2024-03-12"
64
64
title: Change in `wrangler d1 execute` default
@@ -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
@@ -138,9 +138,9 @@ entries:
138
138
- publish_date: "2023-08-19"
139
139
title: Row count now returned per query
140
140
description: |-
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.
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/best-practices/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,
@@ -195,12 +195,12 @@ entries:
195
195
New documentation has been published on how to use D1's support for
196
196
[generated columns](/d1/reference/generated-columns/) to define columns that are
197
197
dynamically generated on write (or read). Generated columns allow you to extract
198
-
data from [JSON objects](/d1/build-with-d1/query-json/) or use the output of other
198
+
data from [JSON objects](/d1/sql-api/query-json/) or use the output of other
199
199
SQL functions.
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.
206
206
- publish_date: "2023-05-19"
@@ -223,7 +223,7 @@ entries:
223
223
- publish_date: "2023-05-17"
224
224
title: Query JSON
225
225
description:
226
-
"[New documentation](/d1/build-with-d1/query-json/) has been published
226
+
"[New documentation](/d1/sql-api/query-json/) has been published
227
227
that covers D1's extensive JSON function support. JSON functions allow you to
228
228
parse, query and modify JSON directly from your SQL queries, reducing the number
229
229
of round trips to your database, or data queried."
Copy file name to clipboardExpand all lines: src/content/docs/d1/best-practices/import-export-data.mdx
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ sidebar:
7
7
8
8
D1 allows you to import existing SQLite tables and their data directly, enabling you to migrate existing data into D1 quickly and easily. This can be useful when migrating applications to use Workers and D1, or when you want to prototype a schema locally before importing it to your D1 database(s).
9
9
10
-
D1 also allows you to export a database. This can be useful for [local development](/d1/build-with-d1/local-development/) or testing.
10
+
D1 also allows you to export a database. This can be useful for [local development](/d1/best-practices/local-development/) or testing.
11
11
12
12
## Import an existing database
13
13
@@ -69,7 +69,7 @@ The `_cf_KV` table is a reserved table used by D1's underlying storage system. I
69
69
70
70
:::
71
71
72
-
From here, you can now query our new table from our Worker [using the D1 client API](/d1/build-with-d1/d1-client-api/).
72
+
From here, you can now query our new table from our Worker [using the D1 Workers Binding API](/d1/worker-api/).
73
73
74
74
:::caution[Known limitations]
75
75
@@ -105,12 +105,6 @@ Once you have run the above command, you will need to edit the output SQL file t
105
105
106
106
You can then follow the steps to [import an existing database](#import-an-existing-database) into D1 by using the `.sql` file you generated from the database dump as the input to `wrangler d1 execute`.
107
107
108
-
## Foreign key constraints
109
-
110
-
When importing data, you may need to temporarily disable [foreign key constraints](/d1/build-with-d1/foreign-keys/). To do so, call `PRAGMA defer_foreign_keys = true` before making changes that would violate foreign keys.
111
-
112
-
Refer to the [foreign key documentation](/d1/build-with-d1/foreign-keys/) to learn more about how to work with foreign keys and D1.
113
-
114
108
## Export an existing D1 database
115
109
116
110
In addition to importing existing SQLite databases, you might want to export a D1 database for local development or testing. You can export a D1 database to a `.sql` file using [wrangler d1 export](/workers/wrangler/commands/#export) and then execute (import) with `d1 execute --file`.
@@ -198,8 +192,14 @@ VALUES
198
192
('1000', 'Boris Pewter', '2022-12-15 22:16:15');
199
193
```
200
194
195
+
## Foreign key constraints
196
+
197
+
When importing data, you may need to temporarily disable [foreign key constraints](/d1/sql-api/foreign-keys/). To do so, call `PRAGMA defer_foreign_keys = true` before making changes that would violate foreign keys.
198
+
199
+
Refer to the [foreign key documentation](/d1/sql-api/foreign-keys/) to learn more about how to work with foreign keys and D1.
200
+
201
201
## Next Steps
202
202
203
203
- Read the SQLite [`CREATE TABLE`](https://www.sqlite.org/lang_createtable.html) documentation.
204
-
- Learn how to [use the D1 client API](/d1/build-with-d1/d1-client-api/) from within a Worker.
204
+
- Learn how to [use the D1 Workers Binding API](/d1/worker-api/) from within a Worker.
205
205
- Understand how [database migrations work](/d1/reference/migrations/) with D1.
0 commit comments