pub struct Store { /* private fields */ }Expand description
The embedded store: a thin typed repository over an embedded SurrealDB instance.
Implementations§
Source§impl Store
impl Store
Sourcepub async fn open(path: &Path) -> Res<Self>
pub async fn open(path: &Path) -> Res<Self>
Opens (or creates) a persistent store rooted at path using the SurrealKV backend.
§Errors
Returns an error if the backend cannot be opened or the schema cannot be applied.
Sourcepub async fn open_in_memory() -> Res<Self>
pub async fn open_in_memory() -> Res<Self>
Opens an ephemeral in-memory store (for tests).
§Errors
Returns an error if the in-memory backend cannot be initialized.
Sourcepub async fn create_user(&self, username: &str) -> Res<UserRecord>
pub async fn create_user(&self, username: &str) -> Res<UserRecord>
Creates a user, enforcing the unique-username constraint.
§Errors
Returns an error if the username is already taken or the write fails.
Sourcepub async fn create_machine(
&self,
user: &str,
name: &str,
pubkey_base64: &str,
) -> Res<MachineRecord>
pub async fn create_machine( &self, user: &str, name: &str, pubkey_base64: &str, ) -> Res<MachineRecord>
Enrolls a machine, enforcing the globally-unique pubkey and per-user-unique name constraints.
§Errors
Returns an error if the pubkey is already enrolled, the name collides within the user, or the write fails.
Sourcepub async fn get_machine_by_pubkey(
&self,
pubkey_base64: &str,
) -> Res<Option<MachineRecord>>
pub async fn get_machine_by_pubkey( &self, pubkey_base64: &str, ) -> Res<Option<MachineRecord>>
Sourcepub async fn list_machines(&self, user: &str) -> Res<Vec<MachineRecord>>
pub async fn list_machines(&self, user: &str) -> Res<Vec<MachineRecord>>
Sourcepub async fn delete_machine(&self, user: &str, name: &str) -> Void
pub async fn delete_machine(&self, user: &str, name: &str) -> Void
Sourcepub async fn create_channel(
&self,
name: &str,
visibility: Visibility,
created_by: &str,
) -> Res<ChannelRecord>
pub async fn create_channel( &self, name: &str, visibility: Visibility, created_by: &str, ) -> Res<ChannelRecord>
Creates a channel, enforcing the unique-name constraint.
§Errors
Returns an error if the name is already taken or the write fails.
Sourcepub async fn get_channel(&self, name: &str) -> Res<Option<ChannelRecord>>
pub async fn get_channel(&self, name: &str) -> Res<Option<ChannelRecord>>
Sourcepub async fn create_invite(
&self,
channel: &str,
token: &str,
uses_remaining: Option<i64>,
expires_at: Option<String>,
created_by: &str,
) -> Res<InviteRecord>
pub async fn create_invite( &self, channel: &str, token: &str, uses_remaining: Option<i64>, expires_at: Option<String>, created_by: &str, ) -> Res<InviteRecord>
Creates an invite token, enforcing the unique-token constraint.
§Errors
Returns an error if the token already exists or the write fails.
Sourcepub async fn get_invite(&self, token: &str) -> Res<Option<InviteRecord>>
pub async fn get_invite(&self, token: &str) -> Res<Option<InviteRecord>>
Sourcepub async fn list_channels(&self) -> Res<Vec<ChannelRecord>>
pub async fn list_channels(&self) -> Res<Vec<ChannelRecord>>
Lists every channel; the caller applies visibility / membership gating (DESIGN.md §6).
§Errors
Returns an error if the query fails.
Sourcepub async fn set_channel_acl(&self, name: &str, acl: &[String]) -> Void
pub async fn set_channel_acl(&self, name: &str, acl: &[String]) -> Void
Replaces a channel’s access-control list (e.g. after an ACL add / invite redeem).
§Errors
Returns an error if the update fails.
Sourcepub async fn set_channel_visibility(
&self,
name: &str,
visibility: Visibility,
) -> Void
pub async fn set_channel_visibility( &self, name: &str, visibility: Visibility, ) -> Void
Sourcepub async fn rename_channel(&self, old: &str, new: &str) -> Void
pub async fn rename_channel(&self, old: &str, new: &str) -> Void
Renames a channel, enforcing the unique-name constraint on the new name.
§Errors
Returns an error if the new name is already taken or the update fails.
Sourcepub async fn delete_channel(&self, name: &str) -> Void
pub async fn delete_channel(&self, name: &str) -> Void
Sourcepub async fn set_invite_uses(&self, token: &str, uses_remaining: i64) -> Void
pub async fn set_invite_uses(&self, token: &str, uses_remaining: i64) -> Void
Sets an invite’s remaining redemptions (used when redeeming a limited-use token).
§Errors
Returns an error if the update fails.
Sourcepub async fn delete_invite(&self, token: &str) -> Void
pub async fn delete_invite(&self, token: &str) -> Void
Deletes an invite token (on revoke or when an exhausted token is redeemed).
§Errors
Returns an error if the delete fails.
Sourcepub async fn list_users(&self) -> Res<Vec<UserRecord>>
pub async fn list_users(&self) -> Res<Vec<UserRecord>>
Sourcepub async fn delete_user(&self, username: &str) -> Void
pub async fn delete_user(&self, username: &str) -> Void
Deletes a user (server-admin user remove); the caller also revokes the user’s machines.
§Errors
Returns an error if the delete fails.
Auto Trait Implementations§
impl Freeze for Store
impl RefUnwindSafe for Store
impl Send for Store
impl Sync for Store
impl Unpin for Store
impl UnsafeUnpin for Store
impl UnwindSafe for Store
Blanket Implementations§
impl<T> AsyncFriendly for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request