Drizzle
Drizzle works well when you want file-based schema discovery, explicit SQL migrations, and typed queries from a generated runtime import. ViteHub keeps Drizzle close to its native workflow and adds only the integration glue around config, schema loading, and migration hooks.
Install Drizzle
Install @vitehub/db, drizzle-orm, drizzle-kit, and the driver package that matches your runtime.
pnpm add https://pkg.pr.new/vite-hub/vitehub/@vitehub/db@main drizzle-orm drizzle-kit @libsql/client
Configure Drizzle
Set db.orm to drizzle, choose a dialect, and provide the connection details for your driver.
export default defineNuxtConfig({
modules: ['@vitehub/db/nuxt'],
db: {
orm: 'drizzle',
dialect: 'sqlite',
connection: {
url: 'file:.data/db/app.sqlite',
},
drizzle: {
migrationsDirs: ['server/db/migrations'],
},
},
})
Define a schema
ViteHub discovers Drizzle schema files automatically. Nitro and Nuxt read from server/db/** by default, while Vite reads from src/db/**.
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
export const posts = sqliteTable('posts', {
id: integer().primaryKey({ autoIncrement: true }),
title: text().notNull(),
})
Query with @vitehub/db/drizzle
Import the generated runtime from @vitehub/db/drizzle. That subpath exports both the configured db client and the discovered schema module.
import { db, schema } from '@vitehub/db/drizzle'
export default defineEventHandler(async () => {
return await db.select().from(schema.posts)
})
Drizzle options
db.drizzle config controls discovery and migration behavior without changing the shared db contract.
| Key | Purpose |
|---|---|
schemaPaths | Adds extra schema entry files to the discovery list. |
migrationsDirs | Points ViteHub at committed SQL migration directories. |
queriesPaths | Applies additional SQL files after migrations. |
casing | Passes Drizzle casing options such as snake_case or camelCase. |
mode | Sets the MySQL mode, such as planetscale. |
@vitehub/db/drizzle runtime import for you. You do not need to hand-wire an alias for the schema or client.Run native Drizzle commands
Drizzle owns schema generation and migration authoring. ViteHub only applies committed files during development and build.
pnpm drizzle-kit generate
pnpm drizzle-kit migrate