Files
mize/marts/generated/src/spacetime/profiles_table.rs

193 lines
6.5 KiB
Rust

// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
#![allow(unused, clippy::all)]
use super::profile_type::Profile;
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
/// Table handle for the table `profiles`.
///
/// Obtain a handle from the [`ProfilesTableAccess::profiles`] method on [`super::RemoteTables`],
/// like `ctx.db.profiles()`.
///
/// Users are encouraged not to explicitly reference this type,
/// but to directly chain method calls,
/// like `ctx.db.profiles().on_insert(...)`.
pub struct ProfilesTableHandle<'ctx> {
imp: __sdk::TableHandle<Profile>,
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
}
#[allow(non_camel_case_types)]
/// Extension trait for access to the table `profiles`.
///
/// Implemented for [`super::RemoteTables`].
pub trait ProfilesTableAccess {
#[allow(non_snake_case)]
/// Obtain a [`ProfilesTableHandle`], which mediates access to the table `profiles`.
fn profiles(&self) -> ProfilesTableHandle<'_>;
}
impl ProfilesTableAccess for super::RemoteTables {
fn profiles(&self) -> ProfilesTableHandle<'_> {
ProfilesTableHandle {
imp: self.imp.get_table::<Profile>("profiles"),
ctx: std::marker::PhantomData,
}
}
}
pub struct ProfilesInsertCallbackId(__sdk::CallbackId);
pub struct ProfilesDeleteCallbackId(__sdk::CallbackId);
impl<'ctx> __sdk::Table for ProfilesTableHandle<'ctx> {
type Row = Profile;
type EventContext = super::EventContext;
fn count(&self) -> u64 {
self.imp.count()
}
fn iter(&self) -> impl Iterator<Item = Profile> + '_ {
self.imp.iter()
}
type InsertCallbackId = ProfilesInsertCallbackId;
fn on_insert(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> ProfilesInsertCallbackId {
ProfilesInsertCallbackId(self.imp.on_insert(Box::new(callback)))
}
fn remove_on_insert(&self, callback: ProfilesInsertCallbackId) {
self.imp.remove_on_insert(callback.0)
}
type DeleteCallbackId = ProfilesDeleteCallbackId;
fn on_delete(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> ProfilesDeleteCallbackId {
ProfilesDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
}
fn remove_on_delete(&self, callback: ProfilesDeleteCallbackId) {
self.imp.remove_on_delete(callback.0)
}
}
pub struct ProfilesUpdateCallbackId(__sdk::CallbackId);
impl<'ctx> __sdk::TableWithPrimaryKey for ProfilesTableHandle<'ctx> {
type UpdateCallbackId = ProfilesUpdateCallbackId;
fn on_update(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
) -> ProfilesUpdateCallbackId {
ProfilesUpdateCallbackId(self.imp.on_update(Box::new(callback)))
}
fn remove_on_update(&self, callback: ProfilesUpdateCallbackId) {
self.imp.remove_on_update(callback.0)
}
}
/// Access to the `identity` unique index on the table `profiles`,
/// which allows point queries on the field of the same name
/// via the [`ProfilesIdentityUnique::find`] method.
///
/// Users are encouraged not to explicitly reference this type,
/// but to directly chain method calls,
/// like `ctx.db.profiles().identity().find(...)`.
pub struct ProfilesIdentityUnique<'ctx> {
imp: __sdk::UniqueConstraintHandle<Profile, __sdk::Identity>,
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
}
impl<'ctx> ProfilesTableHandle<'ctx> {
/// Get a handle on the `identity` unique index on the table `profiles`.
pub fn identity(&self) -> ProfilesIdentityUnique<'ctx> {
ProfilesIdentityUnique {
imp: self
.imp
.get_unique_constraint::<__sdk::Identity>("identity"),
phantom: std::marker::PhantomData,
}
}
}
impl<'ctx> ProfilesIdentityUnique<'ctx> {
/// Find the subscribed row whose `identity` column value is equal to `col_val`,
/// if such a row is present in the client cache.
pub fn find(&self, col_val: &__sdk::Identity) -> Option<Profile> {
self.imp.find(col_val)
}
}
/// Access to the `username` unique index on the table `profiles`,
/// which allows point queries on the field of the same name
/// via the [`ProfilesUsernameUnique::find`] method.
///
/// Users are encouraged not to explicitly reference this type,
/// but to directly chain method calls,
/// like `ctx.db.profiles().username().find(...)`.
pub struct ProfilesUsernameUnique<'ctx> {
imp: __sdk::UniqueConstraintHandle<Profile, String>,
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
}
impl<'ctx> ProfilesTableHandle<'ctx> {
/// Get a handle on the `username` unique index on the table `profiles`.
pub fn username(&self) -> ProfilesUsernameUnique<'ctx> {
ProfilesUsernameUnique {
imp: self.imp.get_unique_constraint::<String>("username"),
phantom: std::marker::PhantomData,
}
}
}
impl<'ctx> ProfilesUsernameUnique<'ctx> {
/// Find the subscribed row whose `username` column value is equal to `col_val`,
/// if such a row is present in the client cache.
pub fn find(&self, col_val: &String) -> Option<Profile> {
self.imp.find(col_val)
}
}
#[doc(hidden)]
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
let _table = client_cache.get_or_make_table::<Profile>("profiles");
_table.add_unique_constraint::<__sdk::Identity>("identity", |row| &row.identity);
_table.add_unique_constraint::<String>("username", |row| &row.username);
}
#[doc(hidden)]
pub(super) fn parse_table_update(
raw_updates: __ws::v2::TableUpdate,
) -> __sdk::Result<__sdk::TableUpdate<Profile>> {
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
__sdk::InternalError::failed_parse("TableUpdate<Profile>", "TableUpdate")
.with_cause(e)
.into()
})
}
#[allow(non_camel_case_types)]
/// Extension trait for query builder access to the table `Profile`.
///
/// Implemented for [`__sdk::QueryTableAccessor`].
pub trait profilesQueryTableAccess {
#[allow(non_snake_case)]
/// Get a query builder for the table `Profile`.
fn profiles(&self) -> __sdk::__query_builder::Table<Profile>;
}
impl profilesQueryTableAccess for __sdk::QueryTableAccessor {
fn profiles(&self) -> __sdk::__query_builder::Table<Profile> {
__sdk::__query_builder::Table::new("profiles")
}
}