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>,
Event: 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>,
Event: 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.
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<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.