This guide assumes familiarity with:
- Database connection basics with Drizzle
- Prisma Postgres serverless database - website
- Prisma Postgres direct connections - docs
- Drizzle PostgreSQL drivers - docs
Prisma Postgres is a serverless database built on unikernels. It has a large free tier, operation-based pricing and no cold starts.
You can connect to it using either the node-postgres or postgres.js drivers for PostgreSQL.
Prisma Postgres also has a serverless driver that will be supported with Drizzle ORM in the future.
Step 1 - Install packages
node-postgres (pg)
postgres.js
npm i drizzle-orm pg
npm i -D drizzle-kit
yarn add drizzle-orm pg
yarn add -D drizzle-kit
pnpm add drizzle-orm pg
pnpm add -D drizzle-kit
bun add drizzle-orm pg
bun add -D drizzle-kit
Step 2 - Initialize the driver and make a query
node-postgres (pg)
postgres.js
// Make sure to install the 'pg' package
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
const db = drizzle({ client: pool });
const result = await db.execute('select 1');
// Make sure to install the 'postgres' package
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
const queryClient = postgres(process.env.DATABASE_URL);
const db = drizzle({ client: queryClient });
const result = await db.execute('select 1');