node-postgres
According to their official website (opens in a new tab), 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 i drizzle-orm pg
npm i -D drizzle-kit @types/pg
There're two ways you can connect to the PostgreSQL with pg
driver - it's either single client
connection or a pool
.
For the built in migrate
function with DDL migrations we and drivers are strongly encourage you to use single client
connection.
For querying purposes feel free to use either client
or pool
based on your business demands.
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);