🪨
damian
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

OptionTypeDescription
connectionStringstringPostgreSQL connection string (required)
driverFactoryDriverFactoryCustom slonik driver factory
interceptorsreadonly Interceptor[]Slonik interceptors (logging, tracing)
typeParsersreadonly 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)
})

On this page