Become a Gold Sponsor

Drizzle <> Vercel Postgres

This guide assumes familiarity with:

According to their official website, Vercel Postgres is a serverless SQL database designed to integrate with Vercel Functions.

Drizzle ORM natively supports both @vercel/postgres serverless driver with drizzle-orm/vercel-postgres package and postgres or pg drivers to access Vercel Postgres through postgesql://

Check out the official Vercel Postgres + Drizzle docs.

Step 1 - Install packages

npm
yarn
pnpm
bun
npm i drizzle-orm @vercel/postgres
npm i -D drizzle-kit

Step 2 - Prepare Vercel Postgres

Setup a project according to the official docs.

Step 3 - Initialize the driver and make a query

import { drizzle } from 'drizzle-orm/connect';

const db = await drizzle("vercel-postgres");

const result = await db.execute('select 1');

If you need a synchronous connection, you can use our additional connection API, where you specify a driver connection and pass it to the Drizzle instance.

import { sql } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';

const db = drizzle(sql)

const result = await db.execute('select 1');

With @vercel/postgres severless package you can access Vercel Postgres from either serverful or serverless environments with no TCP available, like Cloudflare Workers, through websockets.

If youโ€™re about to use Vercel Postgres from a serverfull environment, you can do it either with @vercel/postgres or directly access the DB through postgesql:// with either postgres or pg.

Whatโ€™s next?