Skip to main content

Model

Struct Model 

Source
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

Source

pub fn new() -> Result<Self>

Creates an empty in-memory model.

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Opens or creates a persistent format-v1 model at path.

Source

pub fn open_with(options: OpenOptions) -> Result<Self>

Opens a persistent model with typed options (ADR-006 / ADR-022).

Source

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.

Source

pub fn capabilities(&self) -> StorageCapabilities

Returns capability bits for this model.

Source

pub fn backend(&self) -> StorageBackend

Returns the storage backend for this model.

Source

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.

Source

pub fn storage_backend_available(name: &str) -> Result<bool>

Reports whether a named storage backend is available in this build.

Source

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.

Source

pub fn sync(&self) -> Result<()>

Forces a durable sync (Fjall SyncAll). No-op success for memory models.

Source

pub fn clear(&self) -> Result<()>

Clears all statements (and named graphs) from the model.

Source

pub fn clear_graph(&self, graph_name: impl Into<GraphName>) -> Result<()>

Clears a single graph/context.

Source

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.

Source

pub fn export_nquads_to_path(&self, path: impl AsRef<Path>) -> Result<()>

Exports the model as N-Quads to a filesystem path (archival helper).

Source

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.

Source

pub fn add(&self, statement: impl Into<Triple>) -> Result<bool>

Adds a statement to the default graph.

Source

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.

Source

pub fn insert_quad(&self, quad: Quad) -> Result<bool>

Inserts a fully formed quad into the model.

Source

pub fn remove_quad(&self, quad: &Quad) -> Result<bool>

Removes a fully formed quad from the model.

Source

pub fn remove(&self, statement: impl Into<Triple>) -> Result<bool>

Removes a statement from the default graph.

Source

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.

Source

pub fn contains(&self, statement: TripleRef<'_>) -> Result<bool>

Tests whether the default graph contains a statement.

Source

pub fn contains_in_graph( &self, statement: TripleRef<'_>, graph_name: GraphNameRef<'_>, ) -> Result<bool>

Tests whether a named graph/context contains a statement.

Source

pub fn len(&self) -> Result<usize>

Returns the number of statements across all contexts.

Source

pub fn is_empty(&self) -> Result<bool>

Returns whether the model contains no statements.

Source

pub fn find(&self, pattern: StatementPattern<'_>) -> StatementMatches

Streams quads matching a partial statement/context pattern.

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Model

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Model

§

impl !UnwindSafe for Model

§

impl Freeze for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnsafeUnpin for Model

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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