Official PostgreSQL driver for ObjectStack. Connect to Postgres databases with full SQL support and type safety.
The official PostgreSQL driver provides seamless integration with PostgreSQL databases.
ostack add driver-postgres
import { PostgresDriver } from '@objectstack/driver-postgres';
const db = new PostgresDriver({
host: 'localhost',
port: 5432,
database: 'mydb',
user: 'postgres',
password: 'secret'
});
await db.connect();
const users = await db.query('SELECT * FROM users');
| Option | Type | Required | Description |
|---|---|---|---|
| host | string | Yes | Database host |
| port | number | No | Port (default: 5432) |
| database | string | Yes | Database name |
| user | string | Yes | Username |
| password | string | Yes | Password |
const db = new PostgresDriver({
// ... connection options
pool: {
min: 2,
max: 10
}
});
await db.transaction(async (tx) => {
await tx.query('INSERT INTO users (name) VALUES ($1)', ['Alice']);
await tx.query('INSERT INTO logs (action) VALUES ($1)', ['user_created']);
});
MIT © ObjectStack Team