pub struct Sql<DB: Database>(/* private fields */);Expand description
SQL database executor for event sourcing operations.
A generic wrapper around a SQLx connection pool that implements the
Executor trait for storing and querying events.
§Type Parameters
DB- The SQLx database type (e.g.,sqlx::Sqlite,sqlx::MySql,sqlx::Postgres)
§Example
ⓘ
use evento_sql::Sql;
use sqlx::sqlite::SqlitePoolOptions;
// Create a connection pool
let pool = SqlitePoolOptions::new()
.connect(":memory:")
.await?;
// Convert to Sql executor
let executor: Sql<sqlx::Sqlite> = pool.into();
// Or use the type alias
let executor: evento_sql::Sqlite = pool.into();§Executor Implementation
The Sql type implements Executor with the following operations:
read- Query events with filtering and cursor-based paginationwrite- Persist events with optimistic concurrency controlget_subscriber_cursor- Get the current cursor position for a subscriberis_subscriber_running- Check if a subscriber is active with a specific workerupsert_subscriber- Create or update a subscriber recordacknowledge- Update subscriber cursor after processing events
Trait Implementations§
Source§impl<DB> Executor for Sql<DB>where
DB: Database,
for<'c> &'c mut DB::Connection: Executor<'c, Database = DB>,
SqlxValues: for<'q> IntoArguments<'q, DB>,
String: for<'r> Decode<'r, DB> + Type<DB>,
bool: for<'r> Decode<'r, DB> + Type<DB>,
Vec<u8>: for<'r> Decode<'r, DB> + Type<DB>,
usize: ColumnIndex<DB::Row>,
SqlEvent: for<'r> FromRow<'r, DB::Row>,
impl<DB> Executor for Sql<DB>where
DB: Database,
for<'c> &'c mut DB::Connection: Executor<'c, Database = DB>,
SqlxValues: for<'q> IntoArguments<'q, DB>,
String: for<'r> Decode<'r, DB> + Type<DB>,
bool: for<'r> Decode<'r, DB> + Type<DB>,
Vec<u8>: for<'r> Decode<'r, DB> + Type<DB>,
usize: ColumnIndex<DB::Row>,
SqlEvent: for<'r> FromRow<'r, DB::Row>,
Source§fn read<'life0, 'async_trait>(
&'life0 self,
aggregators: Option<Vec<ReadAggregator>>,
routing_key: Option<RoutingKey>,
args: Args,
) -> Pin<Box<dyn Future<Output = Result<ReadResult<Event>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn read<'life0, 'async_trait>(
&'life0 self,
aggregators: Option<Vec<ReadAggregator>>,
routing_key: Option<RoutingKey>,
args: Args,
) -> Pin<Box<dyn Future<Output = Result<ReadResult<Event>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Queries events with filtering and pagination.
Source§fn get_subscriber_cursor<'life0, 'async_trait>(
&'life0 self,
key: String,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_subscriber_cursor<'life0, 'async_trait>(
&'life0 self,
key: String,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Gets the current cursor position for a subscription.
Source§fn is_subscriber_running<'life0, 'async_trait>(
&'life0 self,
key: String,
worker_id: Ulid,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn is_subscriber_running<'life0, 'async_trait>(
&'life0 self,
key: String,
worker_id: Ulid,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Checks if a subscription is running with the given worker ID.
Source§fn upsert_subscriber<'life0, 'async_trait>(
&'life0 self,
key: String,
worker_id: Ulid,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn upsert_subscriber<'life0, 'async_trait>(
&'life0 self,
key: String,
worker_id: Ulid,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Creates or updates a subscription record.
Source§fn write<'life0, 'async_trait>(
&'life0 self,
events: Vec<Event>,
) -> Pin<Box<dyn Future<Output = Result<(), WriteError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn write<'life0, 'async_trait>(
&'life0 self,
events: Vec<Event>,
) -> Pin<Box<dyn Future<Output = Result<(), WriteError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Persists events atomically. Read more
Source§fn acknowledge<'life0, 'async_trait>(
&'life0 self,
key: String,
cursor: Value,
lag: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn acknowledge<'life0, 'async_trait>(
&'life0 self,
key: String,
cursor: Value,
lag: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Updates subscription cursor after processing events.
Source§fn get_snapshot<'life0, 'async_trait>(
&'life0 self,
aggregator_type: String,
aggregator_revision: String,
id: String,
) -> Pin<Box<dyn Future<Output = Result<Option<(Vec<u8>, Value)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_snapshot<'life0, 'async_trait>(
&'life0 self,
aggregator_type: String,
aggregator_revision: String,
id: String,
) -> Pin<Box<dyn Future<Output = Result<Option<(Vec<u8>, Value)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Retrieves a stored snapshot for an aggregate. Read more
Source§fn save_snapshot<'life0, 'async_trait>(
&'life0 self,
aggregator_type: String,
aggregator_revision: String,
id: String,
data: Vec<u8>,
cursor: Value,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn save_snapshot<'life0, 'async_trait>(
&'life0 self,
aggregator_type: String,
aggregator_revision: String,
id: String,
data: Vec<u8>,
cursor: Value,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stores a snapshot for an aggregate. Read more
Auto Trait Implementations§
impl<DB> Freeze for Sql<DB>
impl<DB> !RefUnwindSafe for Sql<DB>
impl<DB> Send for Sql<DB>
impl<DB> Sync for Sql<DB>
impl<DB> Unpin for Sql<DB>
impl<DB> !UnwindSafe for Sql<DB>
Blanket Implementations§
Source§impl<E> AggregatorExecutor<E> for Ewhere
E: Executor,
impl<E> AggregatorExecutor<E> for Ewhere
E: Executor,
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
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 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>
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