pub struct DbmsContext<M, A = AccessControlList>where
M: MemoryProvider,
A: AccessControl,{ /* 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.
The access-control provider A defaults to AccessControlList.
Runtimes that do not need ACL can use NoAccessControl.
§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 with the default AccessControlList,
initializing the memory manager and loading persisted state.
Source§impl<M, A> DbmsContext<M, A>where
M: MemoryProvider,
A: AccessControl,
impl<M, A> DbmsContext<M, A>where
M: MemoryProvider,
A: AccessControl,
Sourcepub fn with_acl(memory: M) -> Self
pub fn with_acl(memory: M) -> Self
Creates a new DBMS context with a custom access control provider.
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 acl_add(&self, identity: A::Id) -> DbmsResult<()>
pub fn acl_add(&self, identity: A::Id) -> DbmsResult<()>
Adds an identity to the access-control list.
Sourcepub fn acl_remove(&self, identity: &A::Id) -> DbmsResult<()>
pub fn acl_remove(&self, identity: &A::Id) -> DbmsResult<()>
Removes an identity from the access-control list.
Sourcepub fn acl_allowed(&self) -> Vec<A::Id>
pub fn acl_allowed(&self) -> Vec<A::Id>
Returns all identities currently in the access-control list.
Sourcepub fn acl_is_allowed(&self, identity: &A::Id) -> bool
pub fn acl_is_allowed(&self, identity: &A::Id) -> bool
Returns whether the given identity is allowed by the ACL.
Sourcepub fn begin_transaction(&self, owner: Vec<u8>) -> TransactionId
pub fn begin_transaction(&self, owner: Vec<u8>) -> TransactionId
Begins a new transaction for the given owner identity.
Sourcepub fn has_transaction(&self, tx_id: &TransactionId, caller: &[u8]) -> bool
pub fn has_transaction(&self, tx_id: &TransactionId, caller: &[u8]) -> bool
Returns whether the given transaction is owned by the given identity.