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 has_table(&self, name: &str) -> bool
pub fn has_table(&self, name: &str) -> bool
Returns whether name resolves to a registered table.
Sourcepub fn granted(
&self,
id: &A::Id,
table: TableFingerprint,
required: TablePerms,
) -> bool
pub fn granted( &self, id: &A::Id, table: TableFingerprint, required: TablePerms, ) -> bool
Returns whether id is granted required on table.
Sourcepub fn granted_admin(&self, id: &A::Id) -> bool
pub fn granted_admin(&self, id: &A::Id) -> bool
Returns whether id carries the admin bypass flag.
Sourcepub fn granted_manage_acl(&self, id: &A::Id) -> bool
pub fn granted_manage_acl(&self, id: &A::Id) -> bool
Returns whether id carries the manage_acl flag.
Sourcepub fn granted_migrate(&self, id: &A::Id) -> bool
pub fn granted_migrate(&self, id: &A::Id) -> bool
Returns whether id carries the migrate flag.
Sourcepub fn acl_grant(&self, id: A::Id, grant: PermGrant) -> DbmsResult<()>
pub fn acl_grant(&self, id: A::Id, grant: PermGrant) -> DbmsResult<()>
Applies a grant. Does not enforce manage_acl on the caller —
callers must check granted_manage_acl first or use the
Dbms::grant wrapper which self-enforces.
Sourcepub fn acl_revoke(&self, id: &A::Id, revoke: PermRevoke) -> DbmsResult<()>
pub fn acl_revoke(&self, id: &A::Id, revoke: PermRevoke) -> DbmsResult<()>
Applies a revoke. Does not enforce manage_acl on the caller.
Sourcepub fn acl_remove_identity(&self, id: &A::Id) -> DbmsResult<()>
pub fn acl_remove_identity(&self, id: &A::Id) -> DbmsResult<()>
Removes an identity entirely. Does not enforce manage_acl on the
caller.
Sourcepub fn acl_perms(&self, id: &A::Id) -> IdentityPerms
pub fn acl_perms(&self, id: &A::Id) -> IdentityPerms
Returns the IdentityPerms currently held by id.
Sourcepub fn acl_identities(&self) -> Vec<(A::Id, IdentityPerms)>
pub fn acl_identities(&self) -> Vec<(A::Id, IdentityPerms)>
Returns every identity in the ACL together with its perms.
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.