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

SqlxBackend

Struct SqlxBackend 

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

SQL-based backend implementing BackendImpl using sqlx.

This backend supports both SQLite and PostgreSQL through sqlx’s AnyPool.

§Thread Safety

SqlxBackend is Send + Sync as required by BackendImpl. The underlying sqlx pool handles connection pooling and thread safety.

§Test Isolation

For PostgreSQL, each backend instance can use its own schema for test isolation. Use connect_postgres_isolated() to create an isolated backend for testing.

Implementations§

Source§

impl SqlxBackend

Source

pub fn pool(&self) -> &AnyPool

Get a reference to the underlying pool.

Source

pub fn kind(&self) -> DbKind

Get the database kind.

Source

pub fn is_sqlite(&self) -> bool

Check if this backend is using SQLite.

Source

pub fn is_postgres(&self) -> bool

Check if this backend is using PostgreSQL.

Source§

impl SqlxBackend

Source

pub async fn open_sqlite<P: AsRef<Path>>(path: P) -> Result<Self>

Open a SQLite database at the given path.

Creates the database file and schema if they don’t exist.

§Arguments
  • path - Path to the SQLite database file
§Example
use eidetica::backend::database::sql::SqlxBackend;

#[tokio::main]
async fn main() {
    let backend = SqlxBackend::open_sqlite("my_database.db").await.unwrap();
}
Source

pub async fn connect_sqlite(url: &str) -> Result<Self>

Connect to a SQLite database using a connection URL.

§Arguments
  • url - SQLite connection URL (e.g., “sqlite:./my.db”)
Source

pub async fn sqlite_in_memory() -> Result<Self>

Create an in-memory SQLite database (async).

The database exists only for the lifetime of this backend instance. Useful for testing.

§Example
use eidetica::backend::database::sql::SqlxBackend;

#[tokio::main]
async fn main() {
    let backend = SqlxBackend::sqlite_in_memory().await.unwrap();
}
Source§

impl SqlxBackend

Source

pub async fn connect_postgres(url: &str) -> Result<Self>

Connect to a PostgreSQL database using a connection URL.

This connects to the default (public) schema. For test isolation, use connect_postgres_isolated() instead.

§Arguments
  • url - PostgreSQL connection URL (e.g., “postgres://user:pass@localhost/dbname”)
§Example
use eidetica::backend::database::sql::SqlxBackend;

let backend = SqlxBackend::connect_postgres("postgres://localhost/eidetica").await.unwrap();
Source

pub async fn connect_postgres_isolated(url: &str) -> Result<Self>

Connect to a PostgreSQL database with test isolation.

Creates a unique schema for this backend instance, ensuring tests don’t interfere with each other when run in parallel.

§Arguments
  • url - PostgreSQL connection URL (e.g., “postgres://user:pass@localhost/dbname”)
§Example
use eidetica::backend::database::sql::SqlxBackend;

let backend = SqlxBackend::connect_postgres_isolated("postgres://localhost/eidetica").await.unwrap();
// This backend uses its own isolated schema

Trait Implementations§

Source§

impl BackendImpl for SqlxBackend

Source§

fn get<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ID, ) -> Pin<Box<dyn Future<Output = Result<Entry>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves an entry by its unique content-addressable ID. Read more
Source§

fn get_verification_status<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ID, ) -> Pin<Box<dyn Future<Output = Result<VerificationStatus>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Gets the verification status of an entry. Read more
Source§

fn put<'life0, 'async_trait>( &'life0 self, verification_status: VerificationStatus, entry: Entry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores an entry in the database with the specified verification status. Read more
Source§

fn update_verification_status<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ID, verification_status: VerificationStatus, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Updates the verification status of an existing entry. Read more
Source§

fn get_entries_by_verification_status<'life0, 'async_trait>( &'life0 self, status: VerificationStatus, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets all entries with a specific verification status. Read more
Source§

fn get_tips<'life0, 'life1, 'async_trait>( &'life0 self, tree: &'life1 ID, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves the IDs of the tip entries for a given tree. Read more
Source§

fn get_store_tips<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tree: &'life1 ID, store: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Retrieves the IDs of the tip entries for a specific store within a given tree. Read more
Source§

fn get_store_tips_up_to_entries<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tree: &'life1 ID, store: &'life2 str, main_entries: &'life3 [ID], ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Gets the store tips that exist up to a specific set of main tree entries. Read more
Source§

fn all_roots<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieves the IDs of all top-level root entries stored in the backend. Read more
Source§

fn find_merge_base<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tree: &'life1 ID, store: &'life2 str, entry_ids: &'life3 [ID], ) -> Pin<Box<dyn Future<Output = Result<ID>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Finds the merge base (common dominator) of the given entry IDs within a store. Read more
Source§

fn collect_root_to_target<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tree: &'life1 ID, store: &'life2 str, target_entry: &'life3 ID, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Collects all entries from the tree root down to the target entry within a store. Read more
Source§

fn as_any(&self) -> &dyn Any

Returns a reference to the backend instance as a dynamic Any type. Read more
Source§

fn get_tree<'life0, 'life1, 'async_trait>( &'life0 self, tree: &'life1 ID, ) -> Pin<Box<dyn Future<Output = Result<Vec<Entry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves all entries belonging to a specific tree, sorted topologically. Read more
Source§

fn get_store<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tree: &'life1 ID, store: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Entry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Retrieves all entries belonging to a specific store within a tree, sorted topologically. Read more
Source§

fn get_tree_from_tips<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, tree: &'life1 ID, tips: &'life2 [ID], ) -> Pin<Box<dyn Future<Output = Result<Vec<Entry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Retrieves all entries belonging to a specific tree up to the given tips, sorted topologically. Read more
Source§

fn get_store_from_tips<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tree: &'life1 ID, store: &'life2 str, tips: &'life3 [ID], ) -> Pin<Box<dyn Future<Output = Result<Vec<Entry>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Retrieves all entries belonging to a specific store within a tree up to the given tips, sorted topologically. Read more
Source§

fn get_cached_crdt_state<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, entry_id: &'life1 ID, store: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get cached CRDT state for a store at a specific entry. Read more
Source§

fn cache_crdt_state<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, entry_id: &'life1 ID, store: &'life2 str, state: String, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Cache CRDT state for a store at a specific entry. Read more
Source§

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

Clear all cached CRDT states. Read more
Source§

fn get_sorted_store_parents<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, tree_id: &'life1 ID, entry_id: &'life2 ID, store: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Get the store parent IDs for a specific entry and store, sorted by height then ID. Read more
Source§

fn get_path_from_to<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, tree_id: &'life1 ID, store: &'life2 str, from_id: &'life3 ID, to_ids: &'life4 [ID], ) -> Pin<Box<dyn Future<Output = Result<Vec<ID>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Gets all entries between one entry and multiple target entries (exclusive of start, inclusive of targets). Read more
Source§

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

Get the instance metadata. Read more
Source§

fn set_instance_metadata<'life0, 'life1, 'async_trait>( &'life0 self, metadata: &'life1 InstanceMetadata, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Set the instance metadata. Read more
Source§

fn put_verified<'life0, 'async_trait>( &'life0 self, entry: Entry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores an entry with verified status (convenience method for local entries). Read more
Source§

fn put_unverified<'life0, 'async_trait>( &'life0 self, entry: Entry, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores an entry with failed verification status (convenience method for sync scenarios). Read more

Auto Trait Implementations§

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