Skip to main content
The Auth UI Boilerplate uses Drizzle ORM with PostgreSQL to provide type-safe database operations with minimal overhead.

Database Stack

Drizzle ORM

Type-safe ORM with SQL-like syntax

PostgreSQL

Production-ready relational database

Why Drizzle?

Drizzle ORM offers several advantages for this boilerplate:
  • Type Safety: Full TypeScript inference for queries and schema
  • Performance: Generates efficient SQL with minimal overhead
  • Simplicity: SQL-like syntax that’s easy to learn
  • Migration Tools: Built-in migration generation and management
  • Better Auth Integration: Seamlessly works with Better Auth’s schema requirements

Configuration

The database is configured in drizzle.config.ts:
drizzle.config.ts
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schema: "./src/db/schema.ts",
  out: "./src/db/migrations",
  dialect: "postgresql",
  dbCredentials: {
    url: process.env.DATABASE_URL || "postgresql://localhost:5432/app",
  },
});
The DATABASE_URL environment variable should be set in your .env file to point to your PostgreSQL instance.

Database Schema

The schema is defined in src/db/schema.ts and includes five tables that are auto-generated by Better Auth:
  • user - User accounts and profiles
  • session - Active user sessions
  • account - OAuth provider accounts
  • verification - Email verification tokens
  • jwks - JSON Web Key Sets for JWT verification
Learn more about the schema in the Schema documentation.

Basic Usage

Once your schema is defined and pushed to the database, you can query it using Drizzle:
import { db } from "@/db";
import { user } from "@/db/schema";

// Select all users
const users = await db.select().from(user);

// Select with conditions
const specificUser = await db
  .select()
  .from(user)
  .where(eq(user.email, "[email protected]"));

// Insert a new record
const newUser = await db.insert(user).values({
  id: "user_123",
  name: "John Doe",
  email: "[email protected]",
  emailVerified: false,
  createdAt: new Date(),
  updatedAt: new Date(),
});
Better Auth manages user creation automatically. You typically won’t need to manually insert users.

Available Commands

The boilerplate includes several npm scripts for database management:
CommandDescription
npm run db:pushPush schema directly to DB (development)
npm run db:generateGenerate SQL migration files
npm run db:migrateRun pending migrations
npm run db:studioOpen Drizzle Studio (visual DB browser)
Learn more about these commands in the Migrations documentation.

Next Steps

Schema

Explore the complete database schema

Migrations

Learn about database migrations

Adding Tables

Add custom tables to your database

Drizzle Docs

Official Drizzle ORM documentation

Build docs developers (and LLMs) love