Install Drizzle ORM

For detailed steps, refer to https://hub.nuxt.com/docs/recipes/drizzle.

Install Drizzle

pnpm add drizzle-orm
pnpm add -D drizzle-kit

Add the Drizzle configuration file to the project root.

// drizzle.config.ts
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "sqlite",
  schema: "./server/db/schema/index.ts",
  out: "./server/db/migrations",
});

accessing the database

You can access the database instance and schema directly from hub:db:

import { db, schema } from 'hub:db'

And for other utilities:

import { sql, eq, and, or } from 'drizzle-orm'

Add a Convenience Script

To avoid typing the lengthy bun run drizzle-kit generate command every time, add this script to your package.json:

// package.json
{
  "scripts": {
    "db:generate": "nuxt db generate"
  }
}

Later, you can generate schemas by simply running bun run db:generate.