stable

cloudflare-d1

Cloudflare D1 adapter for noy-db — SQLite at the edge inside Cloudflare Workers, speaking the store contract via D1's prepare/bind API.

@noy-db/to-cloudflare-d1 · pnpm add @noy-db/to-cloudflare-d1 SQLite at the edge, running inside Cloudflare Workers.

Shaperecord
Atomic CAS✓
Localityedge
Speedmedium
Persistencedurable

What it does

Accepts a D1Database binding (the one Workers hands you in your runtime environment) and speaks the noy-db store contract via D1's prepare/bind API. No external driver to install — D1 is available directly inside the Workers runtime.

Notes

  • casAtomic: true via UPDATE … WHERE v = ? inside a D1 batch.
  • Record shape, one row per record.
  • Factory: toCloudflareD1(options: D1StoreOptions).

Store-locator descriptor

See store-locator descriptors for the general model. kind: 'cloudflare-d1', class: 'cloud'. address is { binding?, database?, table? }: table maps to tableName; binding (the Workers env.<BINDING> name — note the name collision with the locator's own binding slot below) and database are identity-only, not consumed by the factory. options is { autoMigrate? }. binding.client is required — this store has no client library of its own; resolve() without it throws.

import { cloudflareD1StoreDescriptor, registerCloudflareD1Store } from '@noy-db/to-cloudflare-d1'

const descriptor = cloudflareD1StoreDescriptor({ binding: 'DB', database: 'noydb' })
// later: locator.resolve(descriptor, { binding: { client: env.DB } })

See also