Get started
Overview PostgreSQL Manage schema
Overview Column types Indexes & Constraints Migrations Views Schemas Access your data
Query Select Insert Update Delete Filters Joins Magic sql`` operator Performance
Queries Serverless Advanced
Set Operations Transactions Batch Dynamic query building Read Replicas Custom types Goodies Extensions
ESLint Plugin drizzle-zod drizzle-typebox drizzle-valibot node-postgres
node-postgres
According to the official website, node-postgres is a collection of Node.js modules for interfacing with your PostgreSQL database.
Drizzle ORM natively supports pg
with drizzle-orm/pg
package.
npm
yarn
pnpm
bun
npm i drizzle-orm pg
npm i -D drizzle-kit @types/pg
yarn add drizzle-orm pg
yarn add -D drizzle-kit @types/pg
pnpm add drizzle-orm pg
pnpm add -D drizzle-kit @types/pg
bun add drizzle-orm pg
bun add -D drizzle-kit @types/pg
You can connect to a PostgreSQL database either using a single client
connection or a pool
.
Client connection
Pool connection
import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core";
import { drizzle } from "drizzle-orm/node-postgres";
import { Client } from "pg";
const client = new Client({
connectionString: "postgres://user:password@host:port/db",
});
// or
const client = new Client({
host: "127.0.0.1",
port: 5432,
user: "postgres",
password: "password",
database: "db_name",
});
await client.connect();
const db = drizzle(client);
import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core";
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
const pool = new Pool({
connectionString: "postgres://user:password@host:port/db",
});
// or
const pool = new Pool({
host: "127.0.0.1",
port: 5432,
user: "postgres",
password: "password",
database: "db_name",
});
const db = drizzle(pool);
⚙️
For the built in migrate
function with DDL migrations we strongly encourage you to use max: 1
connection configuration.
For querying purposes feel free to use pool size of your choice based on your business demands.