Skip to content

Commit 611ec74

Browse files
Oxyjunranbel
authored andcommitted
[D1, DO] Adding 52-bit limitation for DO and D1 due to JS number (#21738)
* Adding 52-bit limitation for DO and D1 due to JS number limitation. * Iterating over feedback. * Apply suggestions from code review Co-authored-by: ranbel <[email protected]> --------- Co-authored-by: ranbel <[email protected]>
1 parent 7d27e4d commit 611ec74

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/content/docs/d1/best-practices/import-export-data.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ npx wrangler d1 export <database_name> --remote --table=<table_name> --output=./
149149

150150
- Export is not supported for virtual tables, including databases with virtual tables. D1 supports virtual tables for full-text search using SQLite's [FTS5 module](https://www.sqlite.org/fts5.html). As a workaround, delete any virtual tables, export, and then recreate virtual tables.
151151
- A running export will block other database requests.
152+
- Any numeric value in a column is affected by JavaScript's 52-bit precision for numbers. If you store a very large number (in `int64`), then retrieve the same value, the returned value may be less precise than your original number.
152153

153154
## Troubleshooting
154155

src/content/docs/d1/worker-api/return-object.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,8 @@ return Response.json(returnValue);
9898
"count": 1,
9999
"duration": 1
100100
}
101-
```
101+
```
102+
103+
:::note[Storing large numbers]
104+
Any numeric value in a column is affected by JavaScript's 52-bit precision for numbers. If you store a very large number (in `int64`), then retrieve the same value, the returned value may be less precise than your original number.
105+
:::

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
The Durable Object Storage API allows <GlossaryTooltip term="Durable Object">Durable Objects</GlossaryTooltip> to access transactional and strongly consistent storage. A Durable Object's attached storage is private to its unique instance and cannot be accessed by other objects.
1818

19-
The Durable Object Storage API comes with several methods, including SQL, point-in-time recovery (PITR), key-value (KV), and alarm APIs. Available API methods depend on the storage backend for a Durable Objects class, either [SQLite](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class) or [KV](/durable-objects/reference/durable-objects-migrations/#create-durable-object-class-with-key-value-storage).
19+
The Durable Object Storage API comes with several methods, including SQL, point-in-time recovery (PITR), key-value (KV), and alarm APIs. Available API methods depend on the storage backend for a Durable Objects class, either [SQLite](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class) or [KV](/durable-objects/reference/durable-objects-migrations/#create-durable-object-class-with-key-value-storage).
2020

2121
:::note[Recommended SQLite-backed Durable Objects]
2222
Cloudflare recommends all new Durable Object classes use the [SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class).
@@ -143,12 +143,13 @@ console.log(cursor.toArray()); // prints [{ artistid: 456, artistname: 'Bob' },{
143143

144144
`SqlStorageCursor` has the following properties:
145145

146-
* `columnNames`: <Type text='string[]' />
147-
* The column names of the query in the order they appear in each row array returned by the `raw` iterator.
148-
* `rowsRead`: <Type text='number' />
149-
* The number of rows read so far as part of this SQL `query`. This may increase as you iterate the cursor. The final value is used for [SQL billing](/durable-objects/platform/pricing/#sqlite-storage-backend).
150-
* `rowsWritten`: <Type text='number' />
151-
* The number of rows written so far as part of this SQL `query`. This may increase as you iterate the cursor. The final value is used for [SQL billing](/durable-objects/platform/pricing/#sqlite-storage-backend).
146+
- `columnNames`: <Type text='string[]' />
147+
- The column names of the query in the order they appear in each row array returned by the `raw` iterator.
148+
- `rowsRead`: <Type text='number' />
149+
- The number of rows read so far as part of this SQL `query`. This may increase as you iterate the cursor. The final value is used for [SQL billing](/durable-objects/platform/pricing/#sqlite-storage-backend).
150+
- `rowsWritten`: <Type text='number' />
151+
- The number of rows written so far as part of this SQL `query`. This may increase as you iterate the cursor. The final value is used for [SQL billing](/durable-objects/platform/pricing/#sqlite-storage-backend).
152+
- Any numeric value in a column is affected by JavaScript's 52-bit precision for numbers. If you store a very large number (in `int64`), then retrieve the same value, the returned value may be less precise than your original number.
152153

153154
:::note[SQL transactions]
154155
Note that `sql.exec()` cannot execute transaction-related statements like `BEGIN TRANSACTION` or `SAVEPOINT`. Instead, use the [`ctx.storage.transaction()`](/durable-objects/api/storage-api/#transaction) or [`ctx.storage.transactionSync()`](/durable-objects/api/storage-api/#transactionsync) APIs to start a transaction, and then execute SQL queries in your callback.

0 commit comments

Comments
 (0)