Database

Set up Drizzle or Prisma with `@vitehub/db` and explicit ORM runtime imports.

Use ViteHub Database to configure one ORM through a shared db config across Vite, Nitro, and Nuxt. Choose Drizzle or Prisma for each app, then import the runtime from an explicit subpath instead of the package root.

Each app must choose a single ORM. @vitehub/db does not support mixing Drizzle and Prisma in the same app config.

Getting started

Install the package and your ORM

Terminal
pnpm add https://pkg.pr.new/vite-hub/vitehub/@vitehub/db@main drizzle-orm drizzle-kit @libsql/client

Add the driver package that matches your database runtime:

  • PostgreSQL: pg
  • MySQL: mysql2
  • Embedded PostgreSQL: @electric-sql/pglite
  • SQLite file or Turso: @libsql/client

Choose an integration surface

nuxt.config.ts
export default defineNuxtConfig({
modules: ['@vitehub/db/nuxt'],
})

Configure db

The same top-level db key works across Vite, Nitro, and Nuxt. Pick the ORM you want to use and keep the config focused on that runtime.

nitro.config.ts
import { defineNitroConfig } from 'nitro/config'

export default defineNitroConfig({
  modules: ['@vitehub/db/nitro'],
  db: {
    orm: 'drizzle',
    dialect: 'sqlite',
    connection: {
      url: 'file:.data/db/app.sqlite',
    },
    drizzle: {
      migrationsDirs: ['server/db/migrations'],
    },
  },
})

Import the runtime explicitly

Import the runtime from the ORM subpath you configured. The package root does not export a live database client.

server/api/posts.get.ts
import { db, schema } from '@vitehub/db/drizzle'

export default defineEventHandler(async () => {
  return await db.select().from(schema.posts)
})

Shared config

@vitehub/db keeps the shared config surface small. ORM-specific settings live under db.drizzle or db.prisma.

KeyPurpose
ormSelects drizzle or prisma.
dialectSelects sqlite, postgresql, or mysql.
driverOverrides the default driver for the chosen ORM and dialect.
connectionHolds the connection URL, adapter-specific fields, and optional binding metadata.
applyMigrationsDuringDevApplies committed migrations during local development.
applyMigrationsDuringBuildApplies committed migrations during build when the runtime supports it.

Runtime imports

ViteHub keeps runtime imports explicit:

ImportPurpose
@vitehub/dbConfig, types, and integration wiring.
@vitehub/db/drizzleThe generated Drizzle db client and discovered schema exports.
@vitehub/db/prismaThe generated Prisma client and Prisma re-exports.

Native tooling

ViteHub does not wrap ORM CLIs. Generate and manage migrations with the native toolchain for the ORM you picked.

Terminal
pnpm drizzle-kit generate
pnpm drizzle-kit migrate
ViteHub only applies committed migrations during development or build. It never generates migrations for you.
Drizzle
Configure schema discovery, typed queries, and committed SQL migrations with Drizzle.
Prisma
Configure Prisma Client generation, adapters, and runtime imports with Prisma.
Migrations
See how ViteHub applies committed Drizzle and Prisma migrations during dev and build.
Platform notes
Review driver defaults, hosting behavior, and current runtime limits.