Integrations
Postgres
What it does
Swaps the in-memory adapter for PostgreSQL persistence. Loop state, transitions, and events are stored in Postgres through the same LoopStorageAdapter interface, so loop definitions and business logic remain unchanged.
Quick setup
-
Install
1npm install @loop-engine/adapter-postgres -
Create adapter
1import { PostgresAdapter } from "@loop-engine/adapter-postgres";23const storage = new PostgresAdapter({4 connectionString: process.env.DATABASE_URL!,5 maxConnections: 10,6 ssl: false7}); -
Pass into runtime (before/after)
1"cmt">// Before2const loopSystemDev = await createLoopSystem({3 loops: [procurementLoop]4});56"cmt">// After7const loopSystemProd = await createLoopSystem({8 loops: [procurementLoop],9 storage10});
Schema note
On first startup, the adapter creates required persistence tables:
loop_instancesloop_eventsloop_transitions
Configuration reference
| Option | Type | Default | Description |
|---|---|---|---|
| connectionString | string | required | Postgres connection URL |
| maxConnections | number | 10 | Connection pool size |
| ssl | boolean | false | Enable SSL for connection |
Troubleshooting
-
Connection refused — Verify database host/port and credentials.
-
Migration failed — Adapter user requires
CREATE TABLEprivileges. -
Slow queries — Add targeted indexes for your query paths, for example:
1CREATE INDEX IF NOT EXISTS idx_loop_instances_loop_id2ON loop_instances(loop_id);