Skip to content

feat(store): createDatabaseProvider — driver-agnostic swappable db port#9

Merged
drewstone merged 1 commit into
mainfrom
feat/store-database-provider
Jun 5, 2026
Merged

feat(store): createDatabaseProvider — driver-agnostic swappable db port#9
drewstone merged 1 commit into
mainfrom
feat/store-database-provider

Conversation

@drewstone
Copy link
Copy Markdown
Contributor

First brick of the portable inner shell: a swappable database provider that decouples the agent's persistence from any one driver.

The agent core imports a single db and uses it directly. This makes that db a lazy proxy forwarding to whatever instance the runtime injects via setDatabase(). The same core then runs on:

  • Cloudflare D1setDatabase(drizzle(d1, schema)) (prod)
  • SQLite / miniflare — eval + the portable inner shell that runs in a sandbox without Cloudflare
  • libsql/Turso, Postgres — a future hosted DB

Adding a new database is one adapter + a setDatabase call — none of the modules importing db change. Substrate-free (no D1/drizzle/schema knowledge); binds forwarded methods so this resolves through the proxy. 166 tests (+4).

Consumers wire their db/index.ts onto it and gain setDatabase() alongside the existing setD1().

🤖 Generated with Claude Code

The agent core imports a single `db` and uses it directly; this makes that
`db` a lazy proxy that forwards to whatever database instance the runtime
injects via setDatabase(). The same core then runs on Cloudflare D1 (prod),
SQLite/miniflare (eval + the portable inner shell), or libsql/Turso/Postgres
(future) — adding a DB is one adapter + a setDatabase call, with zero changes
to the modules importing `db`. Substrate-free: knows nothing about D1, drizzle,
or any schema. Binds forwarded methods so `this` resolves through the proxy.
166 tests (+4).
@drewstone drewstone merged commit 23e4e91 into main Jun 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant