Skip to main content

Store

Struct Store 

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

A Roteiro graph store backed by a single SQLite database.

Implementations§

Source§

impl Store

Source

pub fn open(path: &Path) -> Result<Self, StoreError>

Open (creating if absent) a store at path and apply pending migrations.

§Errors

Returns StoreError::Sqlite if the database cannot be opened or a migration fails.

Source

pub fn open_in_memory() -> Result<Self, StoreError>

Open an in-memory store (tests, previews).

§Errors

Returns StoreError::Sqlite if a migration fails.

Source

pub fn schema_version(&self) -> Result<u32, StoreError>

The schema version this store has been migrated to.

§Errors

Returns StoreError::Sqlite on query failure.

Source

pub fn node_count(&self) -> Result<u64, StoreError>

Number of nodes currently in the store.

§Errors

Returns StoreError::Sqlite on query failure.

Source

pub fn edge_count(&self) -> Result<u64, StoreError>

Number of edges currently in the store.

§Errors

Returns StoreError::Sqlite on query failure.

Source

pub fn upsert_node(&self, node: &Node) -> Result<(), StoreError>

Insert or update a node, keyed by its natural Node::key.

§Errors

Returns StoreError::Json if meta cannot be serialized, or StoreError::Sqlite on write failure.

Source

pub fn insert_edge(&self, edge: &Edge) -> Result<(), StoreError>

Insert an edge. Both endpoints must already resolve to nodes.

§Errors

Returns StoreError::InvalidEdge if the provenance/confidence invariant is violated, StoreError::UnknownNode if an endpoint key is absent, or StoreError::Sqlite on write failure.

Source

pub fn apply_factset(&mut self, facts: &FactSet) -> Result<(), StoreError>

Apply a fact set atomically: all nodes are upserted, then all edges are inserted, in a single transaction. On any error nothing is committed.

§Errors

Returns the first error encountered (see Store::upsert_node and Store::insert_edge); the transaction is rolled back.

Source

pub fn sync_state(&self) -> Result<Option<String>, StoreError>

The HEAD tree id recorded at the last successful Store::rebuild, if any. Used by the sync engine to detect an unchanged tree.

§Errors

Returns StoreError::Sqlite on query failure.

Source

pub fn rebuild( &mut self, facts: &FactSet, tree: Option<&str>, ) -> Result<(), StoreError>

Atomically replace the entire graph with facts, recording tree as the synced state (or clearing it when tree is None). All existing nodes and edges are deleted first, so the store reflects exactly the given fact set.

Passing None records no synced tree — distinct from an empty string — so Store::sync_state returns None and a later sync will not spuriously short-circuit.

§Errors

Returns the first error encountered (see Store::apply_factset); on any error nothing is committed.

Source

pub fn get_node(&self, key: &str) -> Result<Option<Node>, StoreError>

Fetch a node by its natural key.

§Errors

Returns StoreError::Sqlite, StoreError::Json, or StoreError::Corrupt if a stored value cannot be decoded.

Source

pub fn all_keys(&self) -> Result<Vec<String>, StoreError>

Every node key in the store, ordered. Useful for whole-graph exports.

§Errors

Returns StoreError::Sqlite on query failure.

Source

pub fn export_factset(&self) -> Result<FactSet, StoreError>

Dump the entire graph as a single FactSet, with nodes and edges in a deterministic order — suitable for a portable, content-stable artifact.

§Errors

Returns StoreError::Sqlite, StoreError::Json, or StoreError::Corrupt on decode failure.

Source

pub fn nodes_by_kind(&self, kind: &NodeKind) -> Result<Vec<Node>, StoreError>

All nodes of a given kind.

§Errors

Returns StoreError::Sqlite, StoreError::Json, or StoreError::Corrupt on decode failure.

Source

pub fn all_nodes(&self) -> Result<Vec<Node>, StoreError>

Every node in the store, ordered by key. Unlike Store::export_factset this decodes no edges, so it is cheap for node-only scans (e.g. search).

§Errors

Returns StoreError::Sqlite, StoreError::Json, or StoreError::Corrupt on decode failure.

Source

pub fn edges_from(&self, key: &str) -> Result<Vec<Edge>, StoreError>

Edges whose source is the node with the given key.

§Errors

Returns StoreError::Sqlite or StoreError::Corrupt on failure.

Source

pub fn edges_to(&self, key: &str) -> Result<Vec<Edge>, StoreError>

Edges whose destination is the node with the given key.

§Errors

Returns StoreError::Sqlite or StoreError::Corrupt on failure.

Source

pub fn edges_by_provenance( &self, provenance: Provenance, ) -> Result<Vec<Edge>, StoreError>

All edges with the given provenance.

§Errors

Returns StoreError::Sqlite or StoreError::Corrupt on failure.

Source

pub fn delete_edges_by_provenance( &self, provenance: Provenance, ) -> Result<u64, StoreError>

Delete all edges with the given provenance, returning how many were removed. Used to re-derive a whole provenance class authoritatively (e.g. inferred edges when re-running inference with different parameters).

§Errors

Returns StoreError::Sqlite on write failure.

Source

pub fn delete_edges_by_src_ref(&self, src_ref: &str) -> Result<u64, StoreError>

Delete all edges carrying the given src_ref, returning how many were removed. Lets one producer of inferred edges (e.g. the embedding layer, or a Graphify import) re-derive its own edges authoritatively without touching edges another producer contributed.

§Errors

Returns StoreError::Sqlite on write failure.

Source

pub fn apply_import_layer( &mut self, src_ref: &str, facts: &FactSet, ) -> Result<ImportApplied, StoreError>

Apply an import layer to the live graph and persist it durably under src_ref, validating as it goes: this ref’s prior edges are cleared (an authoritative re-import), the layer’s nodes are upserted, and each edge is applied only if both endpoints resolve. Dangling edges — cross- references to code that is not present — are dropped, and only the validated (trimmed) layer is persisted, so stale data is never stored.

This is the “validate on import” half; Store::reapply_imports is the “validate on sync” half, re-checking layers against the rebuilt graph.

§Errors

Returns StoreError::Json if facts cannot be (de)serialized, StoreError::InvalidEdge on a malformed edge, or StoreError::Sqlite on write failure.

Source

pub fn delete_import(&self, src_ref: &str) -> Result<bool, StoreError>

Remove the persisted import layer for src_ref, returning whether one existed. Does not remove edges already in the live graph (use Store::delete_edges_by_src_ref for that).

§Errors

Returns StoreError::Sqlite on write failure.

Source

pub fn import_refs(&self) -> Result<Vec<String>, StoreError>

The src_refs of all persisted import layers, ordered.

§Errors

Returns StoreError::Sqlite on query failure.

Source

pub fn reapply_imports(&mut self) -> Result<ImportApplied, StoreError>

Re-apply every persisted import layer on top of the current graph and re-validate it: all import nodes are upserted first (so cross-layer and self references resolve), then each edge is applied; an edge whose endpoint is now absent — a cross-reference to code a sync removed — is pruned from the persisted layer, not merely skipped. So the durable store keeps only still-correct data. Idempotent; safe to run after each rebuild.

§Errors

Returns StoreError::Json if a stored layer cannot be (de)serialized, or StoreError::Sqlite on write failure.

Source

pub fn neighbors( &self, key: &str, dir: Direction, ) -> Result<Vec<Node>, StoreError>

Neighbouring nodes reachable from key in the given direction. Returns an empty vector if the node does not exist.

§Errors

Returns StoreError::Sqlite, StoreError::Json, or StoreError::Corrupt on failure.

Source

pub fn context_cache_get( &self, key: &str, ) -> Result<Option<(String, String)>, StoreError>

Fetch the cached context bundle for key as (fingerprint, json), if present. The caller compares the fingerprint to the node’s current one to decide whether the entry is fresh (see crate::context).

§Errors

Returns StoreError::Sqlite on query failure.

Source

pub fn context_cache_fingerprint( &self, key: &str, ) -> Result<Option<String>, StoreError>

Fetch just the cached fingerprint for key, without reading the (larger) JSON payload — for a cheap freshness check.

§Errors

Returns StoreError::Sqlite on query failure.

Source

pub fn context_cache_put( &self, key: &str, fingerprint: &str, json: &str, ) -> Result<(), StoreError>

Store (or replace) the cached context bundle for key.

§Errors

Returns StoreError::Sqlite on write failure.

Source

pub fn context_cache_delete(&self, key: &str) -> Result<bool, StoreError>

Delete the cached context entry for key, returning whether one existed.

§Errors

Returns StoreError::Sqlite on write failure.

Source

pub fn context_cache_keys(&self) -> Result<Vec<String>, StoreError>

Every key with a cached context entry, ordered. Used to prune entries for nodes that no longer exist.

§Errors

Returns StoreError::Sqlite on query failure.

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl !Sync for Store

§

impl !UnwindSafe for Store

§

impl Send for Store

§

impl Unpin for Store

§

impl UnsafeUnpin 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<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.