Skip to content

AppDbConfig

AppDbConfig<TSchema> = object

Defined in: packages/db/src/create-db.ts:262

App-level db factory configuration. The “constants” — D1 binding, Drizzle schema, cache config — that don’t change between requests.

Returned by createAppDb, called per-request with the user’s resolved grants and identity to produce a fresh permission-aware Db.

TSchema extends Record<string, unknown> = Record<string, unknown>

optional cache: DbConfig["cache"]

Defined in: packages/db/src/create-db.ts:283

Cache configuration shared across every per-request Db. Defaults to { backend: "cache-api" } to match createDb. Pass false to opt out.


d1: D1Database | () => D1Database

Defined in: packages/db/src/create-db.ts:273

The Cloudflare D1 database binding. Pass either the binding directly (for tests, where the mock D1 is in scope at module load) or a () => D1Database getter (for Workers, where env.DB is only available per-request — typical pattern: () => env.get().DB).

The lazy form lets createAppDb() be called once at module-load time even though the binding itself isn’t materialized until the first request, so the entire app shares a single factory definition.


schema: TSchema

Defined in: packages/db/src/create-db.ts:278

Drizzle schema. Same shape as DbConfig.schema — pass import * as schema from "./schema".