pub struct Store { /* private fields */ }Expand description
A Roteiro graph store backed by a single SQLite database.
Implementations§
Source§impl Store
impl Store
Sourcepub fn open(path: &Path) -> Result<Self, StoreError>
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.
Sourcepub fn open_in_memory() -> Result<Self, StoreError>
pub fn open_in_memory() -> Result<Self, StoreError>
Sourcepub fn schema_version(&self) -> Result<u32, StoreError>
pub fn schema_version(&self) -> Result<u32, StoreError>
The schema version this store has been migrated to.
§Errors
Returns StoreError::Sqlite on query failure.
Sourcepub fn node_count(&self) -> Result<u64, StoreError>
pub fn node_count(&self) -> Result<u64, StoreError>
Sourcepub fn edge_count(&self) -> Result<u64, StoreError>
pub fn edge_count(&self) -> Result<u64, StoreError>
Sourcepub fn upsert_node(&self, node: &Node) -> Result<(), StoreError>
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.
Sourcepub fn insert_edge(&self, edge: &Edge) -> Result<(), StoreError>
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.
Sourcepub fn apply_factset(&mut self, facts: &FactSet) -> Result<(), StoreError>
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.
Sourcepub fn get_node(&self, key: &str) -> Result<Option<Node>, StoreError>
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.
Sourcepub fn nodes_by_kind(&self, kind: &NodeKind) -> Result<Vec<Node>, StoreError>
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.
Sourcepub fn edges_from(&self, key: &str) -> Result<Vec<Edge>, StoreError>
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.
Sourcepub fn edges_to(&self, key: &str) -> Result<Vec<Edge>, StoreError>
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.
Sourcepub fn edges_by_provenance(
&self,
provenance: Provenance,
) -> Result<Vec<Edge>, StoreError>
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.
Sourcepub fn neighbors(
&self,
key: &str,
dir: Direction,
) -> Result<Vec<Node>, StoreError>
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.