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

You can connect to a PostgreSQL database either using a single client connection or a pool.

Client connection
Pool connection
index.ts
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);
index.ts
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.