Storage
In-memory and PostgreSQL storage adapters for governance-sdk. Swap backends with one line.
Pluggable storage backends for governance state. In-memory by default, PostgreSQL for production. Import the PostgreSQL adapter from governance-sdk/storage-postgres.
Adapters
| Adapter | Signature | Description |
|---|---|---|
| In-memory (default) | createGovernance({ rules }) — no storage option | All state held in process memory. Zero configuration. Ideal for development, testing, and stateless environments. Data lost on restart. |
| createPostgresStorage | createPostgresStorage({ pool, tablePrefix?, autoMigrate? }) => Promise<PostgresStorage> | PostgreSQL adapter. Pass a pg Pool instance. Durable across restarts. |
In-Memory (Default)
ts
Note: In-memory storage is perfect for development and CI. No database required. All state resets when the process exits.
PostgreSQL
ts
Note: Tables are auto-created with
IF NOT EXISTS. No migrations needed. The adapter uses the standardpgpackage — bring your own Pool with your preferred connection settings.
Switching Backends
The storage interface is identical across backends. Switch from in-memory to PostgreSQL by adding one option — no other code changes.
ts