The D1 binding, from the Worker's env
Optionaloptions: D1AdapterOptions
Entity mapping overrides
When db is not D1-shaped. An
absent binding reads as undefined, and without this check the adapter
would register cleanly, report up from the database health indicator,
and fail every query with a bare TypeError — the failure mode
isD1Database exists to prevent.
ReadonlytransactionD1's deferred batch transaction has no isolation-level surface.
Optionaloptions: TransactionOptionsa handle that buffers writes and flushes them as one batch().
See the transaction discussion on D1Adapter.
Open a non-transactional data source for the named entity.
Entity name (for example 'User')
A data source bound to that entity
Closes the underlying connection (pool).
Reports whether the adapter is connected and usable.
true when ready
Execute a raw query in the backend's own dialect.
Expected row shape
The query text
Optionalparams: unknown[]
Positional parameters
The result rows
A database backend over a Cloudflare D1 binding.
Constructed by the application from its own binding and handed to
DatabasePlugin({ type: 'custom', adapter })— the same wiringKvSessionStoreuses, and for the same reason:DatabasePlugin's options are read when the plugin is constructed, which happens before any application exists, so an adapter published in the service registry could never reach it.Transactions
D1 has no interactive transaction.
BEGIN TRANSACTIONis rejected by the platform outright, andbatch()— which runs a pre-declared list of statements as one SQL transaction, rolling the whole sequence back if any statement fails — is its only unit of atomicity.beginTransaction()therefore buffers every write and flushes the whole buffer as onebatch()atcommit();rollback()discards the buffer and sends nothing. Two consequences, both deliberate and both under test:create()inside a transaction requires an explicit primary key, and throws naming the constraint when one is absent. A deferredINSERTcannot report a generated key to a caller that awaitscreate()before the flush. Outside a transactioncreate()usesRETURNING *and returns the real persisted row, generated columns included.Example
See
https://developers.cloudflare.com/d1/worker-api/d1-database/
Since
0.2.0