Skip to main content

Store

Struct Store 

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

The in-memory corpus database for one CLI invocation.

Implementations§

Source§

impl Store

Source

pub fn flush_plan(self, prj: &Project) -> Result<FlushPlan>

Compute the FlushPlan — no filesystem access. Consumes the store, the final read of an invocation.

Source§

impl Store

Source

pub fn baseline(&mut self) -> Result<Vec<(String, i64, String)>>

Snapshot id -> (dkey, title) for every live document. Captured before user DML so Store::cascade_removals can find what the edit removed (and recover a removed doc’s last-known title for its tombstone).

Source

pub fn cascade_removals( &mut self, pcfg: &ProjectConfig, baseline: &Vec<(String, i64, String)>, ) -> Result<()>

React to a --write that removed documents: for each id present in baseline but no longer in docs, purge any child rows a raw DELETE FROM docs left behind, reserve the id against reuse, and strike every inbound reference to it into a tombstone. Runs before the sync pass, the verify gate, and flush.

Source§

impl Store

Source

pub fn refresh_projections(&mut self, pcfg: &ProjectConfig) -> Result<()>

Rebuild the derived fields/sections/blocks tables from the current authoritative state. fields/sections mirror the [[stats]] corpus shapes; blocks decomposes each body into one row per ## section (+ preamble) for querying into bodies.

Source

pub fn run_user_query( &mut self, sql: &str, params: &[String], ) -> Result<(Vec<String>, Vec<Vec<String>>), String>

Execute user-supplied SQL read-only against the live store. Every statement must be a SELECT — checked on the plan, before anything executes. Returns (labels, stringified rows); Err carries a human-readable problem.

Source

pub fn run_user_write( &mut self, sql: &str, params: &[String], ) -> Result<String, String>

Execute user-supplied write SQL (INSERT/UPDATE/DELETE) against the live store, returning a one-line summary of the row counts. The caller is responsible for gating on verify and flushing — this only mutates the in-memory store. Err carries a human-readable problem.

Every statement must be a DML mutation — checked on the plan, before anything executes, so a compound like INSERT …; DROP TABLE docs is rejected outright. This keeps schema-level statements (CREATE/DROP/ALTER TABLE, indexes) off the authoritative tables the store and flush depend on; the verify gate alone can’t catch them (an empty or reshaped table has no verify problems).

Source§

impl Store

Source

pub fn doc(&mut self, dkey: i64) -> Result<Doc>

Reconstruct a single document.

Source

pub fn all_docs(&mut self) -> Result<Vec<(i64, Doc)>>

Reconstruct every document, in dkey (load/path) order.

Source§

impl Store

Source

pub fn build( prj: &Project, loaded: LoadedCorpus, ) -> Result<(Store, Vec<String>)>

Build the working store from an already-read, already-parsed LoadedCorpus — the medium-agnostic half of loading (no filesystem access). The storage backend reads the medium and calls this.

Source

pub fn exec(&mut self, sql: &str, params: Vec<ParamLiteral>) -> Result<()>

Execute a non-SELECT internal statement.

Source

pub fn select( &mut self, sql: &str, params: Vec<ParamLiteral>, ) -> Result<(Vec<String>, Vec<Vec<GValue>>)>

Execute an internal SELECT; returns (column labels, rows) of the last payload.

Source

pub fn scalar( &mut self, sql: &str, params: Vec<ParamLiteral>, ) -> Result<Option<GValue>>

One-row-one-column SELECT convenience; None when no row or NULL.

Source

pub fn dkey_opt(&mut self, id: &str) -> Result<Option<i64>>

The row key for an id — first match in load (path) order, mirroring Project::find on a corpus with duplicate ids. None if absent.

Source

pub fn dkey_of(&mut self, id: &str) -> Result<i64>

The row key for an id, or a not-found error.

Source

pub fn has_relation( &mut self, id: &str, field: &str, target: &str, ) -> Result<bool>

Whether the doc with id (first in load order) has an entry for target in relation field. false if the id is absent.

Source

pub fn put_doc( &mut self, pcfg: &ProjectConfig, dkey: Option<i64>, doc: &Doc, ) -> Result<i64>

Insert (dkey = None) or replace (Some) a document’s rows. The doc’s path must already be its intended location (absolute, under base). Replacement preserves the row’s load snapshot (orig_*), so flush still diffs against the original file.

Source

pub fn delete_doc(&mut self, dkey: i64) -> Result<()>

Remove a document’s rows entirely (close/retire); flush deletes the file.

Source

pub fn touch(&mut self, dkey: i64, now: &str) -> Result<()>

Stamp the auto-maintained timestamps for a user-initiated edit: always refresh updated; set created only when the document has no created key at all (a wrong-typed value living in fm_fields blocks backfill, exactly like today’s contains_key check). Housekeeping (sync, reconcile, strikes, cleanup) must never call this.

Source

pub fn set_path(&mut self, dkey: i64, relpath: &str) -> Result<()>

Overwrite docs.path directly (the relative form; flush performs the rename). Callers that already know the target path use this to avoid the read in Self::set_canonical_path.

Source

pub fn set_canonical_path( &mut self, pcfg: &ProjectConfig, dkey: i64, ) -> Result<()>

Point docs.path at the canonical layout path for the doc’s id/status (no-op when either is missing, matching save_doc). Flush performs the actual rename.

Source

pub fn retire_id(&mut self, id: &str, title: &str) -> Result<()>

Reserve a retired id with its last-known title; flush writes the ledger.

Source

pub fn doc_ids(&mut self) -> Result<HashSet<String>>

The set of live document ids (the resolution universe for rules::evaluate and reference targets).

Source

pub fn title_of(&mut self, id: &str) -> Result<Option<String>>

The title of the doc with id (first in load order), or None.

Source

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

Highest numeric id across live docs, every relation-map entry (struck or not), and the retired ledger — the global monotonic sequence.

Source

pub fn next_id_for(&mut self, prefix: &str, pad: usize) -> Result<String>

Next id for a type prefix: one past the global max, zero-padded.

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V