Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

The embedded store: a thin typed repository over an embedded SurrealDB instance. Cloning yields another handle to the same database (the inner client is a shared handle).

Implementations§

Source§

impl Store

Source

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.

Source

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.

Source

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.

Source

pub async fn get_user(&self, username: &str) -> Res<Option<UserRecord>>

Fetches a user by username.

§Errors

Returns an error if the query fails.

Source

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.

Source

pub async fn get_machine_by_pubkey( &self, pubkey_base64: &str, ) -> Res<Option<MachineRecord>>

Fetches a machine by its base64 public key.

§Errors

Returns an error if the query fails.

Source

pub async fn list_machines(&self, user: &str) -> Res<Vec<MachineRecord>>

Lists the machines enrolled under a user.

§Errors

Returns an error if the query fails.

Source

pub async fn delete_machine(&self, user: &str, name: &str) -> Void

Revokes a machine by (user, name).

§Errors

Returns an error if the delete fails.

Source

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.

Source

pub async fn get_channel(&self, name: &str) -> Res<Option<ChannelRecord>>

Fetches a channel by name.

§Errors

Returns an error if the query fails.

Source

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.

Source

pub async fn get_invite(&self, token: &str) -> Res<Option<InviteRecord>>

Fetches an invite by token.

§Errors

Returns an error if the query fails.

Source

pub async fn list_invites(&self, channel: &str) -> Res<Vec<InviteRecord>>

The outstanding invites for one channel (the channel-admin audit view).

§Errors

Returns an error if the query fails.

Source

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.

Source

pub async fn add_channel_member(&self, channel: &str, user: &str) -> Void

Adds user to a channel’s membership (its ACL), idempotently. Each membership is its own record under the unique (channel, user) index, so concurrent adds of different users write distinct keys and never contend on a shared row (PRD-0007 T-003); a conflict on the same pair is retried per SurrealDB’s optimistic-concurrency contract.

§Errors

Returns an error if the write keeps conflicting past the retry cap or otherwise fails.

Source

pub async fn remove_channel_member(&self, channel: &str, user: &str) -> Void

Removes user from a channel’s membership; idempotent (removing a non-member is a no-op).

§Errors

Returns an error if the delete keeps conflicting past the retry cap or otherwise fails.

Source

pub async fn is_channel_member(&self, channel: &str, user: &str) -> Res<bool>

Whether user is a member of channel.

§Errors

Returns an error if the query fails.

Source

pub async fn list_user_memberships(&self, user: &str) -> Res<Vec<String>>

The channels user is a member of (for discovery gating, DESIGN.md §6).

§Errors

Returns an error if the query fails.

Source

pub async fn list_channel_members(&self, channel: &str) -> Res<Vec<String>>

The members of a channel (its ACL users).

§Errors

Returns an error if the query fails.

Source

pub async fn add_ban(&self, channel: &str, user: &str) -> Void

Records a channel ban for user; idempotent (banning twice is a no-op). Durable so bans survive a server restart; the hub mirrors them in memory for its lock-guarded checks.

§Errors

Returns an error if the insert keeps conflicting past the retry cap or otherwise fails.

Source

pub async fn remove_ban(&self, channel: &str, user: &str) -> Void

Lifts a channel ban; idempotent (removing an absent ban is a no-op).

§Errors

Returns an error if the delete keeps conflicting past the retry cap or otherwise fails.

Source

pub async fn list_bans(&self) -> Res<Vec<(String, String)>>

Every persisted (channel, user) ban, for loading the hub’s in-memory view at startup.

§Errors

Returns an error if the query fails.

Source

pub async fn list_channel_bans(&self, channel: &str) -> Res<Vec<String>>

The users banned from one channel (the channel-admin audit view).

§Errors

Returns an error if the query fails.

Source

pub async fn list_channels_created_by(&self, user: &str) -> Res<Vec<String>>

The names of the channels created (and administered) by user.

§Errors

Returns an error if the query fails.

Source

pub async fn delete_user_memberships(&self, user: &str) -> Void

Removes every membership held by user (used when a user is removed, DESIGN.md §7).

§Errors

Returns an error if the delete fails.

Source

pub async fn set_channel_visibility( &self, name: &str, visibility: Visibility, ) -> Void

Changes a channel’s visibility tier.

§Errors

Returns an error if the update fails.

Source

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.

Source

pub async fn delete_channel(&self, name: &str) -> Void

Deletes a channel.

§Errors

Returns an error if the delete fails.

Source

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.

Source

pub async fn try_consume_invite_use(&self, token: &str) -> Res<bool>

Atomically consumes one redemption of a limited-use invite: decrements uses_remaining only while it is positive, returning whether a use was claimed. The guarded single-statement update (retried on an optimistic-concurrency conflict) makes concurrent redeemers of the last use mutually exclusive, so a single-use token admits exactly one (PRD-0007 T-003). The caller handles unlimited (None) tokens and expiry; an exhausted token is deleted.

§Errors

Returns an error if the update keeps conflicting past the retry cap or otherwise fails.

Source

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.

Source

pub async fn list_users(&self) -> Res<Vec<UserRecord>>

Lists every registered user (server-admin user list).

§Errors

Returns an error if the query fails.

Source

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.

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>, U: Sized,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
Source§

impl<T> AsyncFriendly for T
where T: Send + Sync + 'static,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Generator<T> for T
where T: Clone,

Source§

fn generate(&mut self) -> T

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool