Drizzle

Configure Drizzle with `@vitehub/db/drizzle`, schema discovery, and committed SQL migrations.

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.

Terminal
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.

nuxt.config.ts
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/**.

server/db/schema.ts
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.

server/api/posts.get.ts
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.

KeyPurpose
schemaPathsAdds extra schema entry files to the discovery list.
migrationsDirsPoints ViteHub at committed SQL migration directories.
queriesPathsApplies additional SQL files after migrations.
casingPasses Drizzle casing options such as snake_case or camelCase.
modeSets the MySQL mode, such as planetscale.
ViteHub generates the @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.

Terminal
pnpm drizzle-kit generate
pnpm drizzle-kit migrate
See Migration behavior for the exact rules ViteHub uses when it applies committed Drizzle migrations and query files.