Skip to main content

PgModelStore

Struct PgModelStore 

Source
pub struct PgModelStore { /* private fields */ }
Expand description

A model store over one named model in a Postgres database.

Implementations§

Source§

impl PgModelStore

Source

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.

Source

pub fn tx_high_water(&mut self) -> Result<i64>

The model’s current improv.model_version.tx, read live.

Source

pub fn loaded_tx(&self) -> Option<i64>

The version this handle last loaded or saved at (None if neither).

Source

pub fn set_loaded_tx(&mut self, tx: Option<i64>)

Adopt tx as the base save_model checks against; None saves unconditionally.

Source

pub fn snapshot(&self) -> Option<&PgSnapshot>

What this handle last loaded or saved: the base save_model diffs against (None if neither).

Source

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.

Source

pub fn reload_model(&mut self) -> Result<Model>

Re-read the model after a StoreError::Conflict.

Source

pub fn load_model(&mut self) -> Result<Model>

Read the whole model (structure, unbound cells, bound fact tables) from one consistent snapshot.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.