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

AdapterSignatureDescription
In-memory (default)createGovernance({ rules }) — no storage optionAll state held in process memory. Zero configuration. Ideal for development, testing, and stateless environments. Data lost on restart.
createPostgresStoragecreatePostgresStorage({ 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 standard pg package — 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