Skip to main content

Crate improv_storage_pg

Crate improv_storage_pg 

Source
Expand description

Persist an Improv Model in Postgres, in the improv.* catalog that the pg_improv extension computes over (design: docs/reviews/2026-10-14-pg-improv-design.md §2, §5).

PgModelStore mirrors improv_storage_mentat::ModelStore method for method. The model is stored normalized: one row per category, item, measure and view, input cells either in their bound fact table (an improv.binding row maps a measure to SELECT dims…, value FROM rel) or, when unbound, in improv.cell. improv.model_version is the optimistic concurrency token.

Encoding (v1; the extension must read the same):

  • measure.formula: written as serde JSON of the Formula AST (the DSL printer lives in the GUI crate); read as JSON or, failing that, as DSL text (Target = expr, what the extension’s improv.define writes);
  • measure.value_type: number | boolean | text | datetime | enum;
  • cell.coord: {"<category id>": <item id>, …};
  • cell values: plain JSON scalars (number, bool, string; datetimes as RFC 3339 strings);
  • lambda.definition: written as serde JSON of the NamedLambda; read as JSON or as Name = LAMBDA(…) text (what improv.define writes);
  • meta.blob: {external_fns, external_calls, scenarios, sql_sources}. Before improv.lambda it also held lambdas, still read for a model with no improv.lambda row.

Structs§

PgModelStore
A model store over one named model in a Postgres database.
PgSnapshot
What a PgModelStore last loaded or saved: the base save_model diffs against, so a save writes only what this client changed. Carry it across handles with PgModelStore::set_snapshot, as with loaded_tx.

Enums§

StoreError

Constants§

CATALOG_SQL
The catalog this client depends on (design §2), created when the pg_improv extension is not installed so a plain Postgres works too.

Functions§

split_model_url
Split postgres://…?model=<name>[&…] into the connection string without the model parameter and the model name (required).

Type Aliases§

Result