ViteHub

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'
  • db is databases.default.db.
  • schema is databases.default.schema.
  • databases.default and every databases.<name> entry expose { db, schema }.

Runtime Resolution

For each database entry, ViteHub resolves the runtime in this order:

  1. Use the active Cloudflare D1 binding when the configured cloudflare.binding exists in the request environment.
  2. Otherwise use db.connection.url through the libSQL driver.
  3. Otherwise throw a named configuration error.

Hosted Output Rules

  • Cloudflare output emits wrangler.json.d1_databases for entries that define cloudflare.databaseId.
  • Cloudflare output requires cloudflare.databaseName whenever cloudflare.databaseId is set.
  • Vercel output requires db.connection.url for every D1-backed named database that must run there.
  • File-based SQLite defaults are for local Vite runtime, not hosted deployment output.
Copyright © 2026