pub struct DbmsContext<M>where
M: MemoryProvider,{ /* private fields */ }Expand description
Owns all mutable DBMS state behind interior-mutable wrappers.
Each component is wrapped in a RefCell so that operations
borrowing different components can coexist without requiring
&mut self on the context.
§Threading
DbmsContext is !Send and !Sync because of the RefCell
wrappers. This is intentional: WASM runtimes (both IC canisters
and WASI preview 1 modules) execute single-threaded, so interior
mutability via RefCell is sufficient and avoids the overhead of
synchronization primitives. Embedders that need multi-threaded
access should wrap the context in their own synchronization layer.
Implementations§
Source§impl<M> DbmsContext<M>where
M: MemoryProvider,
impl<M> DbmsContext<M>where
M: MemoryProvider,
Sourcepub fn new(memory: M) -> Self
pub fn new(memory: M) -> Self
Creates a new DBMS context, initializing the memory manager and loading persisted state.
Sourcepub fn flush(&self) -> DbmsResult<()>
pub fn flush(&self) -> DbmsResult<()>
Publishes changes made through this context to the memory provider.
Providers without durable storage implement this as a no-op. Active transaction overlays remain uncommitted and are not flushed.
Sourcepub fn register_table<T: TableSchema>(&self) -> DbmsResult<TableRegistryPage>
pub fn register_table<T: TableSchema>(&self) -> DbmsResult<TableRegistryPage>
Registers a table schema, persisting it in stable memory.
Sourcepub fn has_table(&self, name: &str) -> bool
pub fn has_table(&self, name: &str) -> bool
Returns whether name resolves to a registered table.
Sourcepub fn begin_transaction(&self) -> TransactionId
pub fn begin_transaction(&self) -> TransactionId
Begins a new transaction and returns its ID.
The engine does not record who opened the transaction: any code that holds the ID can use, commit, or roll it back. An embedder that serves several identities keeps its own ledger from ID to identity and checks it before every transactional call.
Sourcepub fn has_transaction(&self, tx_id: &TransactionId) -> bool
pub fn has_transaction(&self, tx_id: &TransactionId) -> bool
Returns whether tx_id names a transaction that is still open.
Embedders use it to drop ledger entries whose transaction was closed through a path they did not see.