Runtime API
Review DB config shape, default aliases, named database exports, and hosted-output behavior.
Config Shape
@vitehub/db/vite accepts one default database plus an optional named database map:
db: {
connection?: { url?: string, authToken?: string }
drizzle?: {
casing?: 'snake_case' | 'camelCase'
migrationsDirs?: string[]
schemaPaths?: string[]
}
cloudflare?: {
binding?: string
databaseId?: string
previewDatabaseId?: string
databaseName?: string
migrationsDir?: string
migrationsTable?: string
}
databases?: {
analytics?: {
connection?: { url?: string, authToken?: string }
drizzle?: {
casing?: 'snake_case' | 'camelCase'
migrationsDirs?: string[]
schemaPaths?: string[]
}
cloudflare?: {
binding?: string
databaseId?: string
previewDatabaseId?: string
databaseName?: string
migrationsDir?: string
migrationsTable?: string
}
}
}
}
Runtime Exports
import { databases, db, schema } from '@vitehub/db/drizzle'
dbisdatabases.default.db.schemaisdatabases.default.schema.databases.defaultand everydatabases.<name>entry expose{ db, schema }.
Runtime Resolution
For each database entry, ViteHub resolves the runtime in this order:
- Use the active Cloudflare D1 binding when the configured
cloudflare.bindingexists in the request environment. - Otherwise use
db.connection.urlthrough the libSQL driver. - Otherwise throw a named configuration error.
Hosted Output Rules
- Cloudflare output emits
wrangler.json.d1_databasesfor entries that definecloudflare.databaseId. - Cloudflare output requires
cloudflare.databaseNamewhenevercloudflare.databaseIdis set. - Vercel output requires
db.connection.urlfor every D1-backed named database that must run there. - File-based SQLite defaults are for local Vite runtime, not hosted deployment output.

