pub struct Database<M: Memory> { /* private fields */ }Expand description
Admitted database owning the supplier’s exclusive collection lease.
Implementations§
Source§impl<M: Memory> Database<M>
impl<M: Memory> Database<M>
Sourcepub fn begin_maintenance(
self,
transition: &SchemaTransition,
) -> Result<Maintenance<M>, Error>
pub fn begin_maintenance( self, transition: &SchemaTransition, ) -> Result<Maintenance<M>, Error>
Close ordinary access and bind one transition, consuming the live handle. Performs one synchronous manifest replacement after complete preparation. A later trap in the enclosing IC message rolls back the freeze as well.
§Errors
Refuses a transition for another source contract before persistent mutation.
§Panics
Supplier failures during mutation trap the enclosing IC message.
Source§impl<M: Memory> Database<M>
impl<M: Memory> Database<M>
Sourcepub fn create(
memory: RuntimeMemory<M>,
schema: Schema,
incarnation: [u8; 16],
) -> Result<Self, Error>
pub fn create( memory: RuntimeMemory<M>, schema: Schema, incarnation: [u8; 16], ) -> Result<Self, Error>
Sourcepub fn open(memory: RuntimeMemory<M>, schema: Schema) -> Result<Self, Error>
pub fn open(memory: RuntimeMemory<M>, schema: Schema) -> Result<Self, Error>
Open only an exact manifest/compiled-contract match, without mutation. This is not a whole-database integrity scan. Entity metadata is checked when read explicitly or when preparing a write to that entity.
§Errors
Refuses active maintenance, missing/corrupt manifests, foreign contracts or supplier formats.
§Panics
Supplier corruption, including overlong stored keys, traps without repair.
Sourcepub const fn schema(&self) -> &Schema
pub const fn schema(&self) -> &Schema
Borrow the admitted executable description for inspection.
Sourcepub const fn incarnation(&self) -> [u8; 16]
pub const fn incarnation(&self) -> [u8; 16]
Durable database identity, distinct from schema identity.
Sourcepub fn revision<E: Entity>(&self) -> Result<u64, Error>
pub fn revision<E: Entity>(&self) -> Result<u64, Error>
Read the atomic revision of one admitted entity.
§Errors
Refuses unknown entities and malformed revision metadata.
Sourcepub fn cardinality<E: Entity>(&self) -> Result<u64, Error>
pub fn cardinality<E: Entity>(&self) -> Result<u64, Error>
Read the exact maintained whole-entity row count without scanning rows. This trusts atomic entity metadata; it does not validate row/index integrity. Filtered counts and row-validating enumeration use the fluent query API.
§Errors
Refuses unadmitted entities and missing or malformed entity metadata.
§Panics
Supplier corruption may trap; this operation never repairs storage.
Sourcepub fn cardinality_by_name(&self, name: &str) -> Result<u64, Error>
pub fn cardinality_by_name(&self, name: &str) -> Result<u64, Error>
Inspect the maintained whole-entity count by exact admitted schema name.
Like Self::cardinality, this reads metadata without validating rows or indexes.
§Errors
Refuses unknown names and missing or malformed entity metadata.
§Panics
Supplier corruption may trap; this operation never repairs storage.
Sourcepub fn get<E: Entity>(&self, key: E::Key) -> Result<Option<E>, Error>
pub fn get<E: Entity>(&self, key: E::Key) -> Result<Option<E>, Error>
Read a typed primary key without planning a scan.
§Errors
Refuses unadmitted types or malformed rows.
Sourcepub fn page<E: Entity>(
&self,
after: Option<E::Key>,
limit: usize,
) -> Result<Page<E>, Error>
pub fn page<E: Entity>( &self, after: Option<E::Key>, limit: usize, ) -> Result<Page<E>, Error>
Sourcepub fn index_prefix<E: Entity>(
&self,
index: &str,
values: &[IndexValue<'_>],
limit: usize,
) -> Result<Vec<E>, Error>
pub fn index_prefix<E: Entity>( &self, index: &str, values: &[IndexValue<'_>], limit: usize, ) -> Result<Vec<E>, Error>
Read the first bounded collection under an exact, nonempty leading index prefix.
Exact operands obey field bounds and the 512-byte complete-key budget.
Use IndexValue::Absent for an absent optional component. A present-only
unique index refuses absent operands because it does not enumerate those rows.
§Errors
Refuses unknown indexes, mismatched operand types, invalid prefix/limit or inconsistent index entries. This method does not yet return continuation.
Sourcepub fn commit(&mut self, batch: Batch) -> Result<(), Error>
pub fn commit(&mut self, batch: Batch) -> Result<(), Error>
Prepare final state, then synchronously apply rows, indexes, revisions and counts. A normal refusal occurs before persistent writes. Success is not a separate durability point from the surrounding IC message. Empty/no-op batches preserve revisions.
§Errors
Refuses missing/existing rows, duplicate targets, uniqueness/reference violations, corruption or limits. References use the intended final batch state.
§Panics
Supplier failures after the first mutation trap; never catch and continue an IC commit.