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<'_>
impl Writer<'_>
Sourcepub fn register_relation_type(
&mut self,
name: impl Into<String>,
) -> Result<RelationTypeId, DbError>
pub fn register_relation_type( &mut self, name: impl Into<String>, ) -> Result<RelationTypeId, DbError>
Sourcepub fn register_property_key(
&mut self,
name: impl Into<String>,
family: PropertyFamily,
value_type: PropertyType,
) -> Result<PropertyKeyId, DbError>
pub fn register_property_key( &mut self, name: impl Into<String>, family: PropertyFamily, value_type: PropertyType, ) -> Result<PropertyKeyId, DbError>
Sourcepub fn define_projection(
&mut self,
definition: ProjectionDefinition,
) -> Result<ProjectionId, DbError>
pub fn define_projection( &mut self, definition: ProjectionDefinition, ) -> Result<ProjectionId, DbError>
Sourcepub fn define_index(
&mut self,
name: impl Into<String>,
definition: IndexDefinition,
) -> Result<IndexId, DbError>
pub fn define_index( &mut self, name: impl Into<String>, definition: IndexDefinition, ) -> Result<IndexId, DbError>
Sourcepub fn apply_schema(&mut self, schema: &Schema) -> Result<Bound, DbError>
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).
Sourcepub fn create_element(&mut self) -> Result<ElementId, DbError>
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).
Sourcepub fn create_relation(&mut self) -> Result<RelationId, DbError>
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).
Sourcepub fn create_incidence(
&mut self,
relation: RelationId,
element: ElementId,
role: RoleId,
) -> Result<IncidenceId, DbError>
pub fn create_incidence( &mut self, relation: RelationId, element: ElementId, role: RoleId, ) -> Result<IncidenceId, DbError>
Sourcepub fn set_relation_type(
&mut self,
relation: RelationId,
relation_type: RelationTypeId,
) -> Result<(), DbError>
pub fn set_relation_type( &mut self, relation: RelationId, relation_type: RelationTypeId, ) -> Result<(), DbError>
Sourcepub fn upsert_element<T: ValueType>(
&mut self,
index: EqualityIndex<T>,
value: impl Assignable<T>,
) -> Result<ElementId, DbError>
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.
Sourcepub fn upsert_relation<T: ValueType>(
&mut self,
index: EqualityIndex<T>,
value: impl Assignable<T>,
relation_type: RelationTypeId,
endpoints: &[(ElementId, RoleId)],
) -> Result<RelationId, DbError>
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.
Sourcepub fn retain<T: ValueType, V: Assignable<T> + Copy>(
&mut self,
index: EqualityIndex<T>,
keep: &[V],
) -> Result<(), DbError>
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).