Bun-SQLite & D1 Store adapters
inseam ships two first-party Store adapters: @inseam/adapter-store-bun-sqlite for Bun-runtime hosts and @inseam/adapter-store-d1 for Cloudflare Workers. Pick whichever matches the runtime; the rest of inseam doesn’t change. Both adapters share a parameterized conformance harness exported from @inseam/store-contract/testing.
How it fits
Section titled “How it fits”Each adapter wraps a single driver as a StoreAdapter. They are interchangeable from core’s perspective: same contract, same error envelope, same migration semantics. The two exist because the two target runtimes have non-overlapping driver shapes (sync vs. async, embedded vs. binding-supplied) and we want each to be idiomatic on its own runtime rather than papered over.
Both adapters:
- Throw only
AdapterError(withcauseandadapterKind) — higher-level error types are core’s concern. - Implement
batchas a real atomic unit — a SQLite transaction for bun-sqlite,db.batch(...)for D1. - Resolve
batch([])to[]without touching the driver and resolvehealth()tofalse(never throws) on a broken connection.
Key pieces
Section titled “Key pieces”bunSqliteAdapter(path)opens or creates a SQLite database atpath(or":memory:"). Applies WAL,foreign_keys=ON, and a fixedbusy_timeoutat construction. Wraps the syncbun:sqlitedriver to the asyncStoreAdaptershape.kind: "bun-sqlite".d1Adapter(db)captures a Worker-injectedD1Databasebinding and performs no driver work at construction. Normalizes D1’ssuccess: falseenvelopes into thrownAdapterErrors; on batch failure, attachesbatchIndex(from D1 when available, else0) to the wrapped error.kind: "d1".
Exact factory and method contracts: @inseam/adapter-store-bun-sqlite API · @inseam/adapter-store-d1 API · arch/adapters-bun-d1-sqlite/spec.md.
When to use this vs alternatives
Section titled “When to use this vs alternatives”Pick by runtime:
- Bun host (CLI, server, local desktop) →
bunSqliteAdapter. Synchronous driver under the hood, lowest possible latency, single-file durability. - Cloudflare Worker →
d1Adapter. Async by nature, runs against the D1 binding the Worker supplies.
If neither fits — a Node host, a Postgres backend, a remote SQLite proxy — write a new adapter against @inseam/store-contract and run the conformance harness against it before shipping.
See also
Section titled “See also”- LLM summary — dense reference for agents.
- Store — the port these adapters implement.
arch/adapters-bun-d1-sqlite/design.md— why these two adapters and whybun:sqlitefor the local case.arch/adapters-bun-d1-sqlite/spec.md— per-method behavior, error wrapping, acceptance criteria.