Skip to main content

Writer

Struct Writer 

Source
pub struct Writer<'db> { /* private fields */ }
Expand description

Single writer transaction.

Mutations accumulate into a private write overlay layered over the parent snapshot; reads fall through the overlay then the base. commit appends the overlay’s mutation log to the WAL (when dirty) and publishes a fresh snapshot; rollback drops the overlay and appends nothing.

§Performance

Creating and moving a writer is O(1); each mutation is O(log change).

Implementations§

Source§

impl Writer<'_>

Source

pub fn register_role( &mut self, name: impl Into<String>, ) -> Result<RoleId, DbError>

Registers a structural incidence role.

§Errors

Returns DbError when the name already exists or ID allocation fails.

§Performance

This method is O(log role count + name length).

Source

pub fn register_label( &mut self, name: impl Into<String>, ) -> Result<LabelId, DbError>

Registers an element or relation label.

§Errors

Returns DbError when the name already exists or ID allocation fails.

§Performance

This method is O(log label count + name length).

Source

pub fn register_relation_type( &mut self, name: impl Into<String>, ) -> Result<RelationTypeId, DbError>

Registers a relation type.

§Errors

Returns DbError when the name already exists or ID allocation fails.

§Performance

This method is O(log relation type count + name length).

Source

pub fn register_property_key( &mut self, name: impl Into<String>, family: PropertyFamily, value_type: PropertyType, ) -> Result<PropertyKeyId, DbError>

Registers a typed property key.

§Errors

Returns DbError when the name already exists or ID allocation fails.

§Performance

This method is O(log property key count + name length).

Source

pub fn define_projection( &mut self, definition: ProjectionDefinition, ) -> Result<ProjectionId, DbError>

Defines a physical projection.

§Errors

Returns DbError when referenced catalog IDs are unknown, the projection name already exists, or ID allocation fails.

§Performance

This method is O(definition size + catalog lookup cost).

Source

pub fn define_index( &mut self, name: impl Into<String>, definition: IndexDefinition, ) -> Result<IndexId, DbError>

Defines an index.

§Errors

Returns DbError when referenced catalog IDs are unknown, the index name already exists, or ID allocation fails.

§Performance

This method is O(definition size + catalog lookup cost).

Source

pub fn apply_schema(&mut self, schema: &Schema) -> Result<Bound, DbError>

Applies a declarative Schema idempotently (register-or-get every declared item), returning the resolved Bound handle bag. Re-applying the same schema reuses existing ids; a name that already exists with a conflicting shape is a DbError::SchemaConflict.

§Errors

Returns DbError on a shape conflict, an undeclared referenced name (an index’s key, a projection’s role/type), or id-allocation failure.

§Performance

This method is O(declared items × log catalog).

Source

pub fn create_element(&mut self) -> Result<ElementId, DbError>

Creates a canonical element.

§Errors

Returns DbError::IdOverflow when element IDs are exhausted.

§Performance

This method is O(log element change).

Source

pub fn create_relation(&mut self) -> Result<RelationId, DbError>

Creates a canonical relation.

§Errors

Returns DbError::IdOverflow when relation IDs are exhausted.

§Performance

This method is O(log relation change).

Source

pub fn create_incidence( &mut self, relation: RelationId, element: ElementId, role: RoleId, ) -> Result<IncidenceId, DbError>

Creates a canonical incidence.

§Errors

Returns DbError when referenced IDs are unknown or incidence IDs are exhausted.

§Performance

This method is O(log incidence change + reference lookup cost).

Source

pub fn set_relation_type( &mut self, relation: RelationId, relation_type: RelationTypeId, ) -> Result<(), DbError>

Sets a relation type.

§Errors

Returns DbError when the relation or relation type is unknown.

§Performance

This method is O(log relation change + log relation type count).

Source

pub fn upsert_element<T: ValueType>( &mut self, index: EqualityIndex<T>, value: impl Assignable<T>, ) -> Result<ElementId, DbError>

Inserts or updates the element whose value under index equals value, returning its canonical id — reused when an element already carries that identity value (id stable across reconcile), freshly minted (a never-reused id, with the identity property set) otherwise.

§Errors

Returns DbError when index is not an equality index or the value type mismatches the key schema.

§Performance

This method is O(log n + value length) — a probe plus, on a miss, a mint.

Source

pub fn upsert_relation<T: ValueType>( &mut self, index: EqualityIndex<T>, value: impl Assignable<T>, relation_type: RelationTypeId, endpoints: &[(ElementId, RoleId)], ) -> Result<RelationId, DbError>

Inserts or updates the relation whose value under index equals value, returning its canonical id. On a miss it mints the relation, sets its type and identity property, and creates one incidence per (element, role) endpoint; on a hit the existing relation (with its endpoints) is reused unchanged — the identity value encodes the endpoints, so they are immutable.

§Errors

Returns DbError when index is not an equality index, the value type mismatches, or an endpoint element does not exist.

§Performance

This method is O(log n + endpoints) — a probe plus, on a miss, a mint.

Source

pub fn retain<T: ValueType, V: Assignable<T> + Copy>( &mut self, index: EqualityIndex<T>, keep: &[V], ) -> Result<(), DbError>

Tombstones every subject carried by index whose identity value is NOT in keep, cascading each subject’s incidences in O(degree) via the reverse-adjacency index. The prune half of a reconcile: after upserting every desired subject, retain removes the vanished complement.

§Errors

Returns DbError when index is not an equality index or a keep value type mismatches the key schema.

§Performance

This method is O(family size + removed × degree).

Source

pub fn set<T: ValueType>( &mut self, subject: impl Into<PropertySubject>, key: Key<T>, value: impl Assignable<T>, ) -> Result<(), DbError>

Sets a typed property on a subject; the value type is checked at compile time against the key.

§Errors

Returns DbError when the subject is absent, the value is out of range, or the value type mismatches the key schema.

§Performance

This method is O(log change + log keys).

Source

pub fn unset<T: ValueType>( &mut self, subject: impl Into<PropertySubject>, key: Key<T>, ) -> Result<(), DbError>

Removes a typed property from a subject.

§Errors

Returns DbError when the subject is absent or the key is unknown.

§Performance

This method is O(log change + log keys).

Source

pub fn add_label( &mut self, subject: impl Into<PropertySubject>, label: LabelId, ) -> Result<(), DbError>

Adds a label to an element or relation subject.

§Errors

Returns DbError when the subject is absent, the label is unknown, or the subject is an incidence (incidences carry no labels).

§Performance

This method is O(log change + log labels).

Source

pub fn tombstone( &mut self, subject: impl Into<PropertySubject>, ) -> Result<(), DbError>

Tombstones any subject by id, cascading a relation’s or element’s incidences in O(degree) via the reverse-adjacency index.

§Errors

Returns DbError when the subject is not visible.

§Performance

This method is O(log change + degree).

Auto Trait Implementations§

§

impl<'db> !UnwindSafe for Writer<'db>

§

impl<'db> Freeze for Writer<'db>

§

impl<'db> RefUnwindSafe for Writer<'db>

§

impl<'db> Send for Writer<'db>

§

impl<'db> Sync for Writer<'db>

§

impl<'db> Unpin for Writer<'db>

§

impl<'db> UnsafeUnpin for Writer<'db>

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> ErasedDestructor for T
where T: 'static,

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, 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.