Drizzle <> PostgreSQL

WARNING

This page explains concepts available on drizzle versions 1.0.0-beta.2 and higher.


This guide assumes familiarity with:

Drizzle has native support for PostgreSQL connections with the node-postgres driver.

Step 1 - Install packages

npm
yarn
pnpm
bun
npm i drizzle-orm@beta pg
npm i -D drizzle-kit@beta @types/pg

Step 2 - Initialize the driver and make a query

node-postgres
node-postgres with config
// Make sure to install the 'pg' package 
import { drizzle } from 'drizzle-orm/cockroach';

const db = drizzle(process.env.DATABASE_URL);
 
const result = await db.execute('select 1');

If you need to provide your existing driver:

// Make sure to install the 'pg' package 
import { drizzle } from "drizzle-orm/cockroach";
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');

What’s next?