pg (node-postgres)
PostgreSQL driver using node-postgres with connection pooling
Installation
pnpm add pg
Configuration
import { createClient } from "viborm/pg";
const client = createClient({
databaseUrl: process.env.DATABASE_URL,
schema,
});
Options
| Option | Type | Description |
|---|---|---|
pool |
Pool |
Existing pg Pool instance |
options |
PoolConfig |
pg pool configuration |
databaseUrl |
string |
PostgreSQL connection URL |
pgvector |
boolean |
Enable pgvector support |
postgis |
boolean |
Enable PostGIS support |
Using Pool Options
import { createClient } from "viborm/pg";
const client = createClient({
options: {
host: "localhost",
port: 5432,
user: "postgres",
password: "password",
database: "mydb",
max: 20,
},
schema,
});
Using Existing Pool
import { Pool } from "pg";
import { createClient } from "viborm/pg";
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
const client = createClient({
pool,
schema,
});
With pgvector
import { createClient } from "viborm/pg";
const client = createClient({
databaseUrl: process.env.DATABASE_URL,
pgvector: true,
schema,
});
Transactions
pg supports full transactions with savepoints for nested transactions — see Transactions.