pub struct Table<T>{ /* private fields */ }Expand description
A Row-based Store
Table provides a record-oriented storage abstraction for entries in a subtree,
similar to a database table with automatic primary key generation.
§Features
- Automatically generates UUIDv4 primary keys for new records
- Provides CRUD operations (Create, Read, Update, Delete) for record-based data
- Supports searching across all records with a predicate function
§Type Parameters
T: The record type to be stored, which must be serializable, deserializable, and cloneable
This abstraction simplifies working with collections of similarly structured data by handling the details of:
- Primary key generation and management
- Serialization/deserialization of records
- Storage within the underlying CRDT (Doc)
Implementations§
Source§impl<T> Table<T>
impl<T> Table<T>
Sourcepub async fn get(&self, key: impl AsRef<str>) -> Result<T>
pub async fn get(&self, key: impl AsRef<str>) -> Result<T>
Retrieves a row from the Table by its primary key.
This method first checks for the record in the current transaction’s local changes, and if not found, retrieves it from the persistent state.
§Arguments
key- The primary key (UUID string) of the record to retrieve
§Returns
Ok(T)- The retrieved record if foundErr(Error::NotFound)- If no record exists with the given key
§Errors
Returns an error if:
- The record doesn’t exist (
Error::NotFound) - There’s a serialization/deserialization error
Sourcepub async fn insert(&self, row: T) -> Result<String>
pub async fn insert(&self, row: T) -> Result<String>
Inserts a new row into the Table and returns its generated primary key.
This method:
- Generates a new UUIDv4 as the primary key
- Serializes the record
- Stores it in the local transaction
§Arguments
row- The record to insert
§Returns
Ok(String)- The generated UUID primary key as a string
§Errors
Returns an error if there’s a serialization error or the operation fails
Sourcepub async fn set(&self, key: impl AsRef<str>, row: T) -> Result<()>
pub async fn set(&self, key: impl AsRef<str>, row: T) -> Result<()>
Updates an existing row in the Table with a new value.
This method completely replaces the existing record with the provided one. If the record doesn’t exist yet, it will be created with the given key.
§Arguments
key- The primary key of the record to updaterow- The new record value
§Returns
Ok(())- If the update was successful
§Errors
Returns an error if there’s a serialization error or the operation fails
Sourcepub async fn delete(&self, key: impl AsRef<str>) -> Result<bool>
pub async fn delete(&self, key: impl AsRef<str>) -> Result<bool>
Deletes a row from the Table by its primary key.
This method marks the record as deleted using CRDT tombstone semantics, ensuring the deletion is properly synchronized across distributed nodes.
§Arguments
key- The primary key of the record to delete
§Returns
Ok(true)- If a record existed and was deletedOk(false)- If no record existed with the given key
§Errors
Returns an error if there’s a serialization error or the operation fails
Sourcepub async fn search(
&self,
query: impl Fn(&T) -> bool,
) -> Result<Vec<(String, T)>>
pub async fn search( &self, query: impl Fn(&T) -> bool, ) -> Result<Vec<(String, T)>>
Searches for rows matching a predicate function.
§Arguments
query- A function that takes a reference to a record and returns a boolean
§Returns
Ok(Vec<(String, T)>)- A vector of (primary_key, record) pairs that match the predicate
§Errors
Returns an error if there’s a serialization error or the operation fails
Trait Implementations§
Source§impl<T> Registered for Table<T>
impl<T> Registered for Table<T>
Source§impl<T> Store for Table<T>
impl<T> Store for Table<T>
Source§fn new<'life0, 'async_trait>(
txn: &'life0 Transaction,
subtree_name: String,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn new<'life0, 'async_trait>(
txn: &'life0 Transaction,
subtree_name: String,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Store handle associated with a specific transaction. Read moreSource§fn transaction(&self) -> &Transaction
fn transaction(&self) -> &Transaction
Source§fn default_config() -> Doc
fn default_config() -> Doc
Source§fn init<'life0, 'async_trait>(
txn: &'life0 Transaction,
subtree_name: String,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn init<'life0, 'async_trait>(
txn: &'life0 Transaction,
subtree_name: String,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
_index. Read moreSource§fn get_config<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Doc>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_config<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Doc>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
_index subtree. Read moreSource§fn set_config<'life0, 'async_trait>(
&'life0 self,
config: Doc,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn set_config<'life0, 'async_trait>(
&'life0 self,
config: Doc,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
_index subtree. Read moreSource§fn get_height_strategy<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<HeightStrategy>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_height_strategy<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<HeightStrategy>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
_index subtree. Read moreAuto Trait Implementations§
impl<T> Freeze for Table<T>
impl<T> !RefUnwindSafe for Table<T>
impl<T> Send for Table<T>where
T: Send,
impl<T> Sync for Table<T>where
T: Sync,
impl<T> Unpin for Table<T>where
T: Unpin,
impl<T> !UnwindSafe for Table<T>
Blanket Implementations§
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<T> CompatExt for T
impl<T> CompatExt for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more