Store.d1
Cloudflare D1 storage
Creates an atomic store from a Cloudflare D1 database binding.
Usage
import { } from 'mppx'
type = { : .d1. }
export default {
async (: Request, : ) {
const = .(.)
const = await .(, 'request:customer-42:1', .() + 60_000)
return .({ })
},
}Bind the database as DB. Writes use single SQL statements; updates use compare-and-swap, not interactive transactions.
Return type
type ReturnType = Store.AtomicStore- Provides
get,put,delete, atomicupdate, and replay claims; see the AtomicStore contract. - Keep update callbacks synchronous and side-effect-free: conflicts rerun them.
Parameters
database
- Type:
Store.d1.Database
D1 binding with prepare(sql).bind(...values).all() resolving to { results: unknown[] }.
options (optional)
- Type:
Store.sql.Options
| Property | Type | Default | Description |
|---|---|---|---|
createTable (optional) | boolean | true | Creates the table on first use; set false for a migration-managed table. |
keyPrefix (optional) | string | None | Prefix for every backing key. |
maxAttempts (optional) | number | 32 | Maximum compare-and-swap attempts per update. |
table (optional) | string | 'mppx_store' | Valid name or schema.name identifier. |
Uses ox JSON serialization, including bigints. update throws after maxAttempts conflicts. For the default schema and required nullable expires column, see SQL migrations.