pub struct Store { /* private fields */ }Expand description
The in-memory corpus database for one CLI invocation.
Implementations§
Source§impl Store
impl Store
Sourcepub fn baseline(&mut self) -> Result<Vec<(String, i64, String)>>
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).
Sourcepub fn cascade_removals(
&mut self,
pcfg: &ProjectConfig,
baseline: &Vec<(String, i64, String)>,
) -> Result<()>
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
impl Store
Sourcepub fn refresh_projections(&mut self, pcfg: &ProjectConfig) -> Result<()>
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.
Sourcepub fn run_user_query(
&mut self,
sql: &str,
params: &[String],
) -> Result<(Vec<String>, Vec<Vec<String>>), String>
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.
Sourcepub fn run_user_write(
&mut self,
sql: &str,
params: &[String],
) -> Result<String, String>
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
impl Store
Sourcepub fn build(
prj: &Project,
loaded: LoadedCorpus,
) -> Result<(Store, Vec<String>)>
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.
Sourcepub fn exec(&mut self, sql: &str, params: Vec<ParamLiteral>) -> Result<()>
pub fn exec(&mut self, sql: &str, params: Vec<ParamLiteral>) -> Result<()>
Execute a non-SELECT internal statement.
Sourcepub fn select(
&mut self,
sql: &str,
params: Vec<ParamLiteral>,
) -> Result<(Vec<String>, Vec<Vec<GValue>>)>
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.
Sourcepub fn scalar(
&mut self,
sql: &str,
params: Vec<ParamLiteral>,
) -> Result<Option<GValue>>
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.
Sourcepub fn dkey_opt(&mut self, id: &str) -> Result<Option<i64>>
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.
Sourcepub fn dkey_of(&mut self, id: &str) -> Result<i64>
pub fn dkey_of(&mut self, id: &str) -> Result<i64>
The row key for an id, or a not-found error.
Sourcepub fn has_relation(
&mut self,
id: &str,
field: &str,
target: &str,
) -> Result<bool>
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.
Sourcepub fn put_doc(
&mut self,
pcfg: &ProjectConfig,
dkey: Option<i64>,
doc: &Doc,
) -> Result<i64>
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.
Sourcepub fn delete_doc(&mut self, dkey: i64) -> Result<()>
pub fn delete_doc(&mut self, dkey: i64) -> Result<()>
Remove a document’s rows entirely (close/retire); flush deletes the file.
Sourcepub fn touch(&mut self, dkey: i64, now: &str) -> Result<()>
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.
Sourcepub fn set_path(&mut self, dkey: i64, relpath: &str) -> Result<()>
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.
Sourcepub fn set_canonical_path(
&mut self,
pcfg: &ProjectConfig,
dkey: i64,
) -> Result<()>
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.
Sourcepub fn retire_id(&mut self, id: &str, title: &str) -> Result<()>
pub fn retire_id(&mut self, id: &str, title: &str) -> Result<()>
Reserve a retired id with its last-known title; flush writes the ledger.
Sourcepub fn doc_ids(&mut self) -> Result<HashSet<String>>
pub fn doc_ids(&mut self) -> Result<HashSet<String>>
The set of live document ids (the resolution universe for
rules::evaluate and reference targets).
Sourcepub fn title_of(&mut self, id: &str) -> Result<Option<String>>
pub fn title_of(&mut self, id: &str) -> Result<Option<String>>
The title of the doc with id (first in load order), or None.
Sourcepub fn max_doc_num(&mut self) -> Result<i64>
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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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