pub struct PgModelStore { /* private fields */ }Expand description
A model store over one named model in a Postgres database.
Implementations§
Source§impl PgModelStore
impl PgModelStore
Sourcepub fn open(url: &str) -> Result<Self>
pub fn open(url: &str) -> Result<Self>
Connect to postgres://…?model=<name> and open (or create) that model.
Creates the improv.* catalog (CATALOG_SQL) if it is missing.
Sourcepub fn tx_high_water(&mut self) -> Result<i64>
pub fn tx_high_water(&mut self) -> Result<i64>
The model’s current improv.model_version.tx, read live.
Sourcepub fn loaded_tx(&self) -> Option<i64>
pub fn loaded_tx(&self) -> Option<i64>
The version this handle last loaded or saved at (None if neither).
Sourcepub fn set_loaded_tx(&mut self, tx: Option<i64>)
pub fn set_loaded_tx(&mut self, tx: Option<i64>)
Adopt tx as the base save_model checks against; None saves
unconditionally.
Sourcepub fn snapshot(&self) -> Option<&PgSnapshot>
pub fn snapshot(&self) -> Option<&PgSnapshot>
What this handle last loaded or saved: the base save_model diffs
against (None if neither).
Sourcepub fn set_snapshot(&mut self, snapshot: Option<PgSnapshot>)
pub fn set_snapshot(&mut self, snapshot: Option<PgSnapshot>)
Adopt snapshot (e.g. from the handle that loaded) as the save base;
None makes save_model write the whole model, unchecked.
Sourcepub fn reload_model(&mut self) -> Result<Model>
pub fn reload_model(&mut self) -> Result<Model>
Re-read the model after a StoreError::Conflict.
Sourcepub fn load_model(&mut self) -> Result<Model>
pub fn load_model(&mut self) -> Result<Model>
Read the whole model (structure, unbound cells, bound fact tables) from one consistent snapshot.
Sourcepub fn load_partial(&mut self, measure_ids: &[MeasureId]) -> Result<Model>
pub fn load_partial(&mut self, measure_ids: &[MeasureId]) -> Result<Model>
Like Self::load_model, but only the cells of measure_ids and
their dependency closure. Saving the result through this handle
writes only what changed against what it loaded, so the cells it did
not load are left alone.
Sourcepub fn save_model(&mut self, model: &Model) -> Result<()>
pub fn save_model(&mut self, model: &Model) -> Result<()>
Persist the model in ONE transaction and bump improv.model_version.
The save is a diff against this handle’s snapshot (what it last loaded
or saved): structure rows are upserted, and only rows the snapshot
held but the model dropped are deleted (rows another client added
survive); input cells added, changed or removed since are written,
bound ones to their fact table under a per-cell optimistic guard
(a removed one’s value column is set to NULL, the row kept), unbound
ones to improv.cell. Without a snapshot (Self::set_snapshot) the
whole model is written unchecked and rows it lacks are deleted.
Optimistic concurrency: fails with StoreError::Conflict, writing
nothing, if the version moved since this handle loaded or saved, or a
bound cell it writes was changed in the database since.