pub struct Model { /* private fields */ }Expand description
An RDF graph model backed by an Oxigraph store.
In-memory models use Oxigraph alone. Persistent models opened with
Model::open / Model::open_with keep an Oxigraph working set and a
Fjall durable copy under Oxiland format v1 (ADR-006).
Cloning a Model clones the store handle and shares the same dataset; it
does not deep-copy statements. Model is Send and Sync.
Readers (find / query execution) take a shared lock; writers take an
exclusive lock so Fjall reload cannot expose an empty working set.
§Examples
use oxiland::terms::{self, Literal, Triple};
use oxiland::{Model, StatementPattern};
let model = Model::new()?;
let statement = Triple::new(
terms::named_node("https://example.com/alice")?,
terms::named_node("https://example.com/name")?,
Literal::new_simple_literal("Alice"),
);
assert!(model.add(statement.clone())?);
assert!(model.contains(statement.as_ref())?);
let matches = model
.find(StatementPattern {
subject: Some(statement.subject.as_ref()),
..StatementPattern::default()
})
.collect::<Result<Vec<_>, _>>()?;
assert_eq!(matches.len(), 1);Implementations§
Source§impl Model
impl Model
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Opens or creates a persistent format-v1 model at path.
Sourcepub fn open_with(options: OpenOptions) -> Result<Self>
pub fn open_with(options: OpenOptions) -> Result<Self>
Opens a persistent model with typed options (ADR-006 / ADR-022).
Sourcepub fn migrate_legacy_store(path: impl AsRef<Path>) -> Result<Self>
pub fn migrate_legacy_store(path: impl AsRef<Path>) -> Result<Self>
Migrates a pre-0.4 experimental Fjall directory to format v1, then opens it.
Sourcepub fn capabilities(&self) -> StorageCapabilities
pub fn capabilities(&self) -> StorageCapabilities
Returns capability bits for this model.
Sourcepub fn backend(&self) -> StorageBackend
pub fn backend(&self) -> StorageBackend
Returns the storage backend for this model.
Sourcepub fn store(&self) -> &Store
pub fn store(&self) -> &Store
Returns the underlying Oxigraph store.
This is an escape hatch for advanced Oxigraph use. Mutations through the
returned handle bypass Oxiland’s lock and Fjall durability sync.
Prefer Model::insert_quad, Model::transaction, and
crate::Update so memory and disk stay aligned.
Sourcepub fn storage_backend_available(name: &str) -> Result<bool>
pub fn storage_backend_available(name: &str) -> Result<bool>
Reports whether a named storage backend is available in this build.
Sourcepub fn transaction<R>(
&self,
f: impl FnOnce(&mut ModelTransaction<'_>) -> Result<R>,
) -> Result<R>
pub fn transaction<R>( &self, f: impl FnOnce(&mut ModelTransaction<'_>) -> Result<R>, ) -> Result<R>
Runs f inside an Oxigraph transaction; Fjall models sync on commit.
Same-thread Model reads (len / find / Query::execute) during the
callback see the last committed working set and do not deadlock. Use
ModelTransaction methods for in-transaction mutations. Nested
transaction / auto-commit writes return Error::Unsupported.
Sourcepub fn sync(&self) -> Result<()>
pub fn sync(&self) -> Result<()>
Forces a durable sync (Fjall SyncAll). No-op success for memory models.
Sourcepub fn clear_graph(&self, graph_name: impl Into<GraphName>) -> Result<()>
pub fn clear_graph(&self, graph_name: impl Into<GraphName>) -> Result<()>
Clears a single graph/context.
Sourcepub fn bulk_insert_quads(
&self,
quads: impl IntoIterator<Item = Quad>,
) -> Result<usize>
pub fn bulk_insert_quads( &self, quads: impl IntoIterator<Item = Quad>, ) -> Result<usize>
Inserts many quads inside a single transaction (then durable sync).
Returns the number of quads in the input iterator (including duplicates that were already present), not the count of newly inserted quads.
Sourcepub fn export_nquads_to_path(&self, path: impl AsRef<Path>) -> Result<()>
pub fn export_nquads_to_path(&self, path: impl AsRef<Path>) -> Result<()>
Exports the model as N-Quads to a filesystem path (archival helper).
Sourcepub fn import_nquads_from_path(&self, path: impl AsRef<Path>) -> Result<usize>
pub fn import_nquads_from_path(&self, path: impl AsRef<Path>) -> Result<usize>
Imports N-Quads from a path inside a transaction (atomic on success).
Quads are merged into the existing model (RDF union); this does not clear the store first. A leading UTF-8 BOM is skipped when present.
Sourcepub fn add(&self, statement: impl Into<Triple>) -> Result<bool>
pub fn add(&self, statement: impl Into<Triple>) -> Result<bool>
Adds a statement to the default graph.
Sourcepub fn add_to_graph(
&self,
statement: impl Into<Triple>,
graph_name: impl Into<GraphName>,
) -> Result<bool>
pub fn add_to_graph( &self, statement: impl Into<Triple>, graph_name: impl Into<GraphName>, ) -> Result<bool>
Adds a statement to a named graph/context.
Sourcepub fn insert_quad(&self, quad: Quad) -> Result<bool>
pub fn insert_quad(&self, quad: Quad) -> Result<bool>
Inserts a fully formed quad into the model.
Sourcepub fn remove_quad(&self, quad: &Quad) -> Result<bool>
pub fn remove_quad(&self, quad: &Quad) -> Result<bool>
Removes a fully formed quad from the model.
Sourcepub fn remove(&self, statement: impl Into<Triple>) -> Result<bool>
pub fn remove(&self, statement: impl Into<Triple>) -> Result<bool>
Removes a statement from the default graph.
Sourcepub fn remove_from_graph(
&self,
statement: impl Into<Triple>,
graph_name: impl Into<GraphName>,
) -> Result<bool>
pub fn remove_from_graph( &self, statement: impl Into<Triple>, graph_name: impl Into<GraphName>, ) -> Result<bool>
Removes a statement from a named graph/context.
Sourcepub fn contains(&self, statement: TripleRef<'_>) -> Result<bool>
pub fn contains(&self, statement: TripleRef<'_>) -> Result<bool>
Tests whether the default graph contains a statement.
Sourcepub fn contains_in_graph(
&self,
statement: TripleRef<'_>,
graph_name: GraphNameRef<'_>,
) -> Result<bool>
pub fn contains_in_graph( &self, statement: TripleRef<'_>, graph_name: GraphNameRef<'_>, ) -> Result<bool>
Tests whether a named graph/context contains a statement.
Sourcepub fn find(&self, pattern: StatementPattern<'_>) -> StatementMatches ⓘ
pub fn find(&self, pattern: StatementPattern<'_>) -> StatementMatches ⓘ
Streams quads matching a partial statement/context pattern.