Drivers
PostgreSQL
PostgreSQL driver configuration and usage
Setup
createDb returns a Promise<DatabasePool>, always await it:
import { createDb, createSQL } from '@damiandb/pg'
export const db = await createDb({
connectionString: process.env.DATABASE_URL as string
})
export const sql = createSQL()Options
| Option | Type | Description |
|---|---|---|
connectionString | string | PostgreSQL connection string (required) |
driverFactory | DriverFactory | Custom slonik driver factory |
interceptors | readonly Interceptor[] | Slonik interceptors (logging, tracing) |
typeParsers | readonly DriverTypeParser[] | Custom type parsers for PostgreSQL OIDs |
Custom driver
Damian uses slonik under the hood, so any slonik-compatible driverFactory works.
Example with PGlite for in-process testing:
import { createPGLiteDriverFactory } from 'slonik-pglite-driver'
import { PGlite } from '@electric-sql/pglite'
import { createDb } from '@damiandb/pg'
const pglite = new PGlite()
export const db = await createDb({
connectionString: 'postgres://',
driverFactory: createPGLiteDriverFactory(pglite)
})