Connect a Next.js app to DBHost with Drizzle ORM and query PostgreSQL through the pooled database URL.
If you want PostgreSQL in Next.js without a heavier ORM layer, Drizzle is the clean middle path: typed schema, typed queries, and SQL that still feels close to the database.This quickstart keeps to the shortest useful path: one DBHost database, one Drizzle setup, and one server-side query.Best fit: Teams that want type-safe SQL, explicit schema files, and a lighter abstraction than Prisma.Not for: Teams that want full ORM modeling, or teams that want zero schema tooling and prefer plain SQL only.If you want to compare this path with Prisma or plain pg, start with the Next.js + PostgreSQL guide.
Create a database from the dashboard, then copy the connection string from the database detail page.If you are starting from zero, that is still the fastest first step. DBHost gives you the host, port, username, and password before you touch schema files or query code.
If your team already uses migration files, keep that workflow. Drizzle also supports generate and migrate when you want reviewed SQL migrations in source control.
// app/lib/db.tsimport { drizzle } from "drizzle-orm/node-postgres";import { Pool } from "pg";import * as schema from "./schema";const globalForDb = globalThis as unknown as { pool?: Pool;};const pool = globalForDb.pool ?? new Pool({ connectionString: process.env.DATABASE_URL, });if (process.env.NODE_ENV !== "production") { globalForDb.pool = pool;}export const db = drizzle(pool, { schema });
This keeps development refreshes from creating a new connection pool every time the module reloads.