Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica

Table

Struct Table 

Source
pub struct Table<T>
where T: Serialize + for<'de> Deserialize<'de> + Clone,
{ /* 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>
where T: Serialize + for<'de> Deserialize<'de> + Clone + Send + Sync,

Source

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 found
  • Err(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
Source

pub async fn insert(&self, row: T) -> Result<String>

Inserts a new row into the Table and returns its generated primary key.

This method:

  1. Generates a new UUIDv4 as the primary key
  2. Serializes the record
  3. 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

Source

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 update
  • row - 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

Source

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 deleted
  • Ok(false) - If no record existed with the given key
§Errors

Returns an error if there’s a serialization error or the operation fails

Source

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>
where T: Serialize + for<'de> Deserialize<'de> + Clone,

Source§

fn type_id() -> &'static str

Returns a unique identifier for this type. Read more
Source§

fn supports_type_id(type_id: &str) -> bool

Check if this type supports loading from a stored type_id. Read more
Source§

impl<T> Store for Table<T>
where T: Serialize + for<'de> Deserialize<'de> + Clone + Send + Sync,

Source§

type Data = Doc

The CRDT data type used for local (staged) data in this store. Read more
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,

Creates a new Store handle associated with a specific transaction. Read more
Source§

fn name(&self) -> &str

Returns the name of this subtree.
Source§

fn transaction(&self) -> &Transaction

Returns a reference to the transaction this Store is associated with. Read more
Source§

fn default_config() -> Doc

Returns the default configuration for this Store type as a Doc. Read more
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,

Initializes a new subtree and registers it in the _index. Read more
Source§

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,

Gets the current configuration for this Store from the _index subtree. Read more
Source§

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,

Sets the configuration for this Store in the _index subtree. Read more
Source§

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,

Gets the height strategy for this Store from the _index subtree. Read more
Source§

fn set_height_strategy<'life0, 'async_trait>( &'life0 self, strategy: Option<HeightStrategy>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sets the height strategy for this Store in the _index subtree. Read more
Source§

fn local_data(&self) -> Result<Option<Self::Data>>

Returns the local (staged) data for this store from the current transaction. Read more

Auto 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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