Database
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
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
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.
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.
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.
| Key | Purpose |
|---|---|
orm | Selects drizzle or prisma. |
dialect | Selects sqlite, postgresql, or mysql. |
driver | Overrides the default driver for the chosen ORM and dialect. |
connection | Holds the connection URL, adapter-specific fields, and optional binding metadata. |
applyMigrationsDuringDev | Applies committed migrations during local development. |
applyMigrationsDuringBuild | Applies committed migrations during build when the runtime supports it. |
Runtime imports
ViteHub keeps runtime imports explicit:
| Import | Purpose |
|---|---|
@vitehub/db | Config, types, and integration wiring. |
@vitehub/db/drizzle | The generated Drizzle db client and discovered schema exports. |
@vitehub/db/prisma | The 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.
pnpm drizzle-kit generate
pnpm drizzle-kit migrate