Drizzle PostgreSQL Starter
The Drizzle PostgreSQL Starter is a database foundation provided by servercn for projects that use PostgreSQL with Drizzle ORM. When you run:
Installation Guide
npx servercn init drizzle-pg-starteryou get a production‑ready PostgreSQL + Drizzle setup that integrates cleanly with the Express Server Foundation.
This starter focuses on type‑safe database access, clear schema ownership, and predictable migrations, without hiding SQL or introducing heavy abstractions.
What This Starter Solves
Setting up Drizzle with PostgreSQL repeatedly involves:
- Database connection management
- Schema organization
- Migration configuration
- Environment‑based credentials
- Type safety across queries
The Drizzle PostgreSQL Starter standardizes these concerns using a minimal, explicit setup.
What You Get Out of the Box
After initialization, your project includes:
Database Core
- Drizzle ORM configured for PostgreSQL
- Type‑safe schema definitions
- Centralized database client
Configuration
- Environment‑based database config
- Safe startup validation
- Production‑ready connection handling
Migrations
- Drizzle migration setup
- Structured migration folder
- CLI‑ready workflow
Developer Experience
- Fully typed queries
- Clean schema organization
- Zero runtime magic
Environment Configuration
Database credentials are loaded via environment variables.
NODE_ENV='development'
PORT='9000'
LOG_LEVEL='info'
DATABASE_URL=PostgreSQL://root:password@localhost:3306/db-nameThe server fails fast if required database variables are missing.
Defining Schemas
Schemas are written using Drizzle’s SQL‑first, type‑safe API.
src/drizzle/schema.ts
import { PgTable, serial, varchar } from "drizzle-orm/pg-core";
export const usersTable = PgTable("users_table", {
id: serial().primaryKey(),
name: varchar({ length: 255 }).notNull(),
email: varchar({ length: 255 }).notNull().unique(),
password: varchar("password", { length: 255 }).notNull()
});Schemas are:
- Explicit
- Version‑controlled
- Fully typed across queries
Database Client Setup
src/configs/db.ts or src/db/db.ts
import { drizzle } from "drizzle-orm/node-postgres";
import env from "./env";
const db = drizzle(env.DATABASE_URL!);
export default db;No repositories or hidden layers — you interact directly with Drizzle.
Migrations Workflow
Generate migrations
npm run db:generateApply migrations
npm run db:migrateMigrations are SQL‑first and fully auditable.
Database Studio
npm run db:studioSummary
The Drizzle PostgreSQL Starter gives you a clean, production‑ready database foundation using PostgreSQL + Drizzle ORM.
It prioritizes clarity, type safety, and long‑term maintainability — without taking control away from you.