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 |
namespace |
string |
PostgreSQL schema for VibORM-owned objects (default public) |
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,
});
Namespace
namespace selects the PostgreSQL schema holding this driver’s tables,
junctions, indexes, ORM-managed enums, and migration tracking table. Omitted, it
is public.
import { createClient } from "viborm/postgres";
const db = createClient({
databaseUrl: process.env.DATABASE_URL,
namespace: "billing",
schema,
});
Generated SQL is always qualified, so routing never depends on the connection’s
search_path — including a search_path set through postgres.js options:
SELECT "user"."id" FROM "billing"."user" AS "user"
A supplied Sql client is bound the same way; the namespace comes from the
option, never from inspecting the client. postgres.js reserves a connection with
reserve(), so it supports the full migration verb set against the selected
schema.
Raw SQL is never rewritten and keeps ordinary search_path semantics — see
Namespaces.
Transactions
postgres.js supports full transactions with automatic savepoints for nested transactions — see Transactions.