Drizzle ORM | Postgres.js (opens in a new tab) driver
Installation
Connection
import { drizzle, PostgresJsDatabase } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
const client = postgres(connectionString);
const db: PostgresJsDatabase = drizzle(client);See main docs for further usage.
Running migrations
In order to run the migrations, you need to use max: 1 in the postgres.js connection options (opens in a new tab). You can create a separate connection instance for migrations with that setting.
import postgres from 'postgres';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
const migrationsClient = postgres(connectionString, {
max: 1,
});
const db = drizzle(migrationsClient);
await migrate(db, { migrationsFolder: '...' });See main migrations docs for further info.