DSAR
Persistence

Postgres

@dsar/persistence-pg provides a Postgres driver for DSAR persistence with advisory-lock migration protection, connection pooling, and full domain record support.

Installation

Package managerCommand
npmnpm install @dsar/persistence-pg
pnpmpnpm add @dsar/persistence-pg
yarnyarn add @dsar/persistence-pg
bunbun add @dsar/persistence-pg

Quickstart

Standalone Service

The simplest way to get started — creates a persistence service you can pass directly to the backend:

import { makePgPersistenceService } from "@dsar/persistence-pg";
import { dsarInstance, runtimeReposFromPersistence } from "@dsar/backend";

const persistence = await makePgPersistenceService({
	connectionUrl: "postgres://user:pass@localhost:5432/dsar",
});

const runtime = dsarInstance({
	repos: runtimeReposFromPersistence(persistence),
});

Effect Layer Composition

For Effect-based applications, use the layer API for dependency injection:

import { Effect } from "effect";
import { Persistence, withTenant } from "@dsar/persistence";
import { makePgPersistenceLayer } from "@dsar/persistence-pg";

const program = Persistence.pipe(
	Effect.flatMap((persistence) => persistence.requests.list()),
	withTenant("tenant-1"),
	Effect.provide(
		makePgPersistenceLayer({
			config: { url: "postgres://user:pass@localhost:5432/dsar" },
		})
	)
);

await Effect.runPromise(program);

Migrations

Migrations run automatically on startup with advisory-lock protection to prevent concurrent migration conflicts in multi-instance deployments.