Skip to content

Commit a66ef8b

Browse files
committed
Adding 52-bit limitation for DO and D1 due to JS
number limitation.
1 parent a69a7dc commit a66ef8b

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

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+
D1 returns numbers as a [JavaScript number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), which has a 52-bit precision. 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+
- `SqlStorageCursor` returns numbers as a [JavaScript number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), which has a 52-bit precision. 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)