Integrations
Postgres
Archetype: Store — implements LoopStore, slotted at options.store.
What it does
Swaps the in-memory adapter for PostgreSQL persistence. Loop state, transitions, and events are stored in Postgres through the same LoopStore interface, so loop definitions and business logic remain unchanged.
Quick setup
-
Install
1npm install @loop-engine/adapter-postgres -
Create a
LoopStorewithpostgresStore1"cmt">// @no-typecheck2import { createPool, postgresStore } from "@loop-engine/adapter-postgres";3import { createLoopSystem } from "@loop-engine/sdk";45const pool = createPool({ connectionString: process.env.DATABASE_URL! });6const store = postgresStore(pool);7const { engine } = await createLoopSystem({8 loops: [procurementLoop],9 store10}); -
Local vs production pattern
1"cmt">// Dev: in-memory (default) — omit `store`2const dev = await createLoopSystem({ loops: [procurementLoop] });34"cmt">// Prod: pass `store: postgresStore(pool)` as above
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);