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