@xlambda-tech/postgres
v0.2.0
Published
xlambda managed PostgreSQL SDK: provisioning, sub-users, backups, and a getPool() convenience.
Downloads
59
Readme
@xlambda-tech/postgres
Provision and manage xlambda-managed PostgreSQL databases.
import { PostgresClient } from '@xlambda-tech/postgres';
const client = new PostgresClient({ apiKey: process.env.XLAMBDA_API_KEY! });
const db = await client.databases.create({ projectId, name: 'my-app-db' });
console.log(db.connectionString); // shown once - store it now
const pool = await db.getPool(); // configured pg.Pool, ready to use
const { rows } = await pool.query('select 1');getPool() uses the PgBouncer/transaction-pooled port (6432) — the right
default for app steady-state traffic. Use getSessionPool() (port 6433,
direct session) for migrations, DDL, advisory locks, or anything needing
prepared statements, which transaction pooling breaks.
pg is an optional peer dependency — only required if you call
getPool()/getSessionPool(). Everything else (provisioning, users,
backups) has no dependency on it.
Sub-users and backups
const readonly = await client.databases.users(db.id).create({ permission: 'readonly' });
const backup = await client.databases.backups(db.id).create();Not covered — use the dashboard
The SQL console (arbitrary query execution, schema introspection, saved
queries, table browser CRUD) is deliberately not wrapped here — it's built
for the web dashboard's UI, not for calling from your own backend code. A
real application should connect with getPool()/getSessionPool() and use
pg (or an ORM) directly, the same as it would against any other Postgres
database.
