A Nuxt module that brings Drizzle ORM to the Nuxt server layer, built on top of nitro-drizzle.
nuxt-drizzle is a thin Nuxt integration layer around nitro-drizzle. It wires Drizzle into Nitro's server runtime — handling config discovery, migration execution, type generation, server virtual modules, and asset bundling — so you can work with one or many Drizzle datasources directly inside your Nuxt server routes and plugins.
- 🧩 First-class
nitro-drizzleintegration for Nuxt - 🗄️ Multiple datasources (e.g.
sqlite,postgresql,mysql) in a single app - 🚀 Automatic migrations on server init (
migrateOnInit) - 🔌 Configurable connectors and drivers (e.g.
pglite,sqlite) - 🧠 Typed
useDatasource()access from server routes and Nitro plugins - 🛠️ Zero-config type templates and virtual modules generated on the fly
.
├── fixtures/nuxt-app/ # Fixture Nuxt app used as the base for the playground and e2e tests
├── playground/ # Runnable Nuxt app for local development and trying the module
├── test/e2e/ # End-to-end tests for datasource functionality
├── src/ # Module source
└── dist/ # Built module output
fixtures/nuxt-app/— A fixture Nuxt app that demonstrates the module with two datasources (contentusing sqlite,usersusing pglite). It extendsnitro-drizzle-blog-api-legacy-layerfor API routes and uses@nuxt/uifor the frontend. Both the playground and e2e tests extend this fixture.playground/— A runnable Nuxt app that extends the fixtures app withinstall: true. It overrides datasource drivers to use in-memory drivers (:memory:/memory://) for local development. Runpnpm run devfrom the repo root to start it.test/e2e/— End-to-end tests that extend the fixtures app and verify datasource functionality via$fetch.
Install the module to your Nuxt application with one command:
npx nuxt module add nuxt-drizzleThen register it in nuxt.config.ts and configure your datasource drivers via runtimeConfig:
export default defineNuxtConfig({
modules: ["nuxt-drizzle"],
runtimeConfig: {
drizzle: {
users: {
driver: "pglite",
pglite: {
dataDir: "./data/users",
},
},
content: {
driver: "sqlite",
sqlite: {
url: "./data/content.db",
},
},
},
},
});Define a datasource with defineConfig from nitro-drizzle/config:
// server/drizzle/users/drizzle-pglite.config.ts
import { defineConfig } from "nitro-drizzle/config";
export default defineConfig(
{
strict: true,
dialect: "postgresql",
schema: ["./pg/schema/users.ts"],
out: "./pg/migrations",
},
import.meta.url,
);Use it from a server route via nitro-drizzle/runtime:
// server/api/v1/users.get.ts
import { useDatasource } from "nitro-drizzle/runtime";
export default defineEventHandler(async (event) => {
await event.context.drizzle.waitReady();
const { database, schema } = await useDatasource("users");
const users = await database.select().from(schema.users).limit(10);
return { users };
});That's it! You can now use nuxt-drizzle in your Nuxt app ✨
Under the hood, all database wiring, migrations, and runtime helpers come from
nitro-drizzle. See its docs for the full configuration reference (nitro-drizzle/config,nitro-drizzle/runtime,nitro-drizzle/utils).
Run the playground app to try the module locally:
# Install dependencies
pnpm install
# Generate type stubs
pnpm run dev:prepare
# Start the playground dev server
pnpm run devThe playground at playground/ extends fixtures/nuxt-app and uses in-memory drivers for quick iteration.
The fixture app at fixtures/nuxt-app/ provides a full Nuxt app with two datasources and UI pages. It is used as the base for both the playground and e2e tests.
Run the e2e tests to verify datasource functionality:
pnpm run testLocal development
# Install dependencies
pnpm install
# Generate type stubs
pnpm run dev:prepare
# Develop with the playground
pnpm run dev
# Build the playground
pnpm run dev:build
# Run Vitest
pnpm run test
pnpm run test:watch
# Run type checks
pnpm run test:types
# Run ESLint
pnpm run lint
# Format code
pnpm run fmt
# Check formatting
pnpm run fmt:check
# Release new version
pnpm run release