pub struct BuiltIn<DB: BuiltInDialect>(/* private fields */);Expand description
The dialect built into the crate for the database DB: what SqlxBroker::new builds its
statements with.
It builds them with the dialect of the crate’s dialect module that serves
the database: Postgres on Postgres,
MySql on MySQL and MariaDB, Sqlite on
SQLite. On an AnyPool it is the dialect of the database the pool reaches, among those whose
features are on, picked when the broker connects.
It serves the forms its database serves, through the traits of the dialect module: every
BuiltIn implements Lease and Advisory, and BuiltIn<Postgres>, BuiltIn<MySql> and
BuiltIn<Any> implement RowLock. A SQLite table in the row lock form therefore does not
compile. An AnyPool names its database only when the broker connects, so on a SQLite backend
the subscription to a row lock table stops when it starts, with
StatementError::UnsupportedForm.
It opens transactions at the isolation levels and SQLite modes its database keeps, one
Opens per level: BuiltIn<Postgres> READ COMMITTED, REPEATABLE
READ and SERIALIZABLE, BuiltIn<MySql> those and READ UNCOMMITTED, BuiltIn<Sqlite> the three
modes. A table that names another does not compile. BuiltIn<Any> takes all seven, and the
picked backend’s dialect refuses the ones its database lacks when the subscription starts,
with StatementError::UnsupportedOpening.
§Examples
use ruststream_sqlx::BuiltIn;
use ruststream_sqlx::prelude::*;
use serde::Deserialize;
use sqlx::{PgPool, Postgres};
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "email_jobs")]
pub struct SendEmail {
#[field(id, generated)]
job_id: i64,
#[field(group)]
name: String,
#[field(payload)]
payload: Vec<u8>,
}
#[derive(Deserialize)]
struct Email {
to: String,
}
#[subscriber(InboxQueue::<SendEmail>::new("emails"))]
async fn send(email: &Email) -> HandlerOutcome {
tracing::info!(to = %email.to, "sending");
HandlerOutcome::ack()
}
// `SqlxBroker<Postgres>` names the same type: the built-in dialect is the default.
pub fn broker(pool: PgPool) -> SqlxBroker<Postgres, BuiltIn<Postgres>> {
SqlxBroker::new(pool)
}
pub fn app(pool: PgPool) -> RustStream {
RustStream::new(AppInfo::new("mailer", "0.1.0")).with_broker(broker(pool), |b| {
b.include(send);
})
}Trait Implementations§
Source§impl<DB: BuiltInDialect> Advisory for BuiltIn<DB>
impl<DB: BuiltInDialect> Advisory for BuiltIn<DB>
Source§fn advisory_claim(
&self,
spec: &TableSpec<'_>,
) -> Result<Statement, StatementError>
fn advisory_claim( &self, spec: &TableSpec<'_>, ) -> Result<Statement, StatementError>
Param::Limit claimable rows of the
subscription’s group in claim order, two columns each, the id and the lock key as text
(named __lock). It takes no lock and writes nothing; where the database can tell, it
leaves out the rows whose key another session holds. Read moreSource§fn lock(&self) -> Option<Statement>
fn lock(&self) -> Option<Statement>
Param::Key for the session, without waiting: one
row whose first column is a 64-bit integer, nonzero when the lock was taken. None when the
process keeps the locks. Read moreSource§fn unlock(&self) -> Option<Statement>
fn unlock(&self) -> Option<Statement>
Param::Key: one row whose first column is a
64-bit integer, nonzero when the session held it. None when the process keeps the locks. Read moreSource§fn take(
&self,
spec: &TableSpec<'_>,
shape: ClaimShape,
) -> Result<Vec<Statement>, StatementError>
fn take( &self, spec: &TableSpec<'_>, shape: ClaimShape, ) -> Result<Vec<Statement>, StatementError>
shape, as it was before the count, only
while it is still claimable. The last returns the row, or none when the row is gone or no
longer claimable; a first statement, where there are two, counts the attempt and changes no row
in that case. Read moreSource§impl ByName<Any> for BuiltIn<Any>
Available on crate feature any only.
impl ByName<Any> for BuiltIn<Any>
any only.Source§impl ByName<MySql> for BuiltIn<MySql>
impl ByName<MySql> for BuiltIn<MySql>
Source§impl ByName<Postgres> for BuiltIn<Postgres>
impl ByName<Postgres> for BuiltIn<Postgres>
Source§impl ByName<Sqlite> for BuiltIn<Sqlite>
impl ByName<Sqlite> for BuiltIn<Sqlite>
Source§impl<DB: BuiltInDialect> Clone for BuiltIn<DB>
impl<DB: BuiltInDialect> Clone for BuiltIn<DB>
impl<DB: BuiltInDialect> Copy for BuiltIn<DB>
Source§impl<DB: BuiltInDialect> Debug for BuiltIn<DB>
impl<DB: BuiltInDialect> Debug for BuiltIn<DB>
Source§impl<DB: BuiltInDialect> Dialect for BuiltIn<DB>
impl<DB: BuiltInDialect> Dialect for BuiltIn<DB>
Source§fn quote_into(&self, ident: &str, out: &mut String)
fn quote_into(&self, ident: &str, out: &mut String)
Source§fn placeholder_into(&self, index: NonZeroUsize, out: &mut String)
fn placeholder_into(&self, index: NonZeroUsize, out: &mut String)
Source§fn fetch(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
fn fetch(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
Source§fn ack(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
fn ack(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
processed_at when the
table has that column. Read moreSource§fn retry(
&self,
spec: &TableSpec<'_>,
) -> Result<Option<Statement>, StatementError>
fn retry( &self, spec: &TableSpec<'_>, ) -> Result<Option<Statement>, StatementError>
None when releasing
the row needs no statement. Read moreSource§fn retry_after(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
fn retry_after(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
Param::RetryAfter. Read moreSource§fn discard(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
fn discard(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
processed_at when the table
has that column. Read moreSource§fn dead_letter_group(
&self,
spec: &TableSpec<'_>,
) -> Result<Statement, StatementError>
fn dead_letter_group( &self, spec: &TableSpec<'_>, ) -> Result<Statement, StatementError>
Param::Destination. Read moreSource§fn dead_letter_table(
&self,
spec: &TableSpec<'_>,
target: TableName<'_>,
) -> Result<Vec<Statement>, StatementError>
fn dead_letter_table( &self, spec: &TableSpec<'_>, target: TableName<'_>, ) -> Result<Vec<Statement>, StatementError>
target, a table with the same
columns; they run in one transaction. Read moreSource§fn insert(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
fn insert(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
TableSpec::columns, each bound as Param::Column. Read moreSource§fn server_version(&self) -> Option<&'static str>
fn server_version(&self) -> Option<&'static str>
None when the
dialect’s statements run on every version of its server. Read moreSource§fn check_server(
&self,
spec: &TableSpec<'_>,
version: &str,
) -> Result<(), StatementError>
fn check_server( &self, spec: &TableSpec<'_>, version: &str, ) -> Result<(), StatementError>
spec need; version is what the
server_version query returned. Read moreSource§fn begin(
&self,
opening: Opening,
) -> Result<Option<&'static str>, StatementError>
fn begin( &self, opening: Opening, ) -> Result<Option<&'static str>, StatementError>
opening in place of BEGIN, or None when
BEGIN opens it. Read moreSource§fn savepoint(&self) -> &'static str
fn savepoint(&self) -> &'static str
Source§fn rollback_to_savepoint(&self) -> &'static str
fn rollback_to_savepoint(&self) -> &'static str
Source§fn fifo_guard(
&self,
spec: &TableSpec<'_>,
) -> Result<Option<Statement>, StatementError>
fn fifo_guard( &self, spec: &TableSpec<'_>, ) -> Result<Option<Statement>, StatementError>
None for a table without FIFO groups, or a dialect that
takes no group. Read moreSource§impl<DB: BuiltInDialect> Lease for BuiltIn<DB>
impl<DB: BuiltInDialect> Lease for BuiltIn<DB>
Source§fn lease_claim(
&self,
spec: &TableSpec<'_>,
shape: ClaimShape,
) -> Result<Statement, StatementError>
fn lease_claim( &self, spec: &TableSpec<'_>, shape: ClaimShape, ) -> Result<Statement, StatementError>
Param::Limit rows of the
subscription’s group, in claim order, among the rows whose lease ended by
Param::LeaseNow. Read moreSource§fn extend(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
fn extend(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
Param::Lease) while the row still holds the delivery’s token
(Param::Held), so a handler that runs longer than one lease keeps
its row. Read moreSource§fn stamp(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
fn stamp(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>
Param::Lease) and counts the attempt, while no lease holds the
row at Param::LeaseNow. Read moreSource§fn claim_writes_lease(&self) -> bool
fn claim_writes_lease(&self) -> bool
Source§fn claim_counts_attempt(&self, spec: &TableSpec<'_>) -> bool
fn claim_counts_attempt(&self, spec: &TableSpec<'_>) -> bool
spec returns carry the attempt the claim counted. A
dialect whose claim returns the rows as they were before answers false; where it answers
true, a delivery reports one less than its row carries. Read moreimpl Opens<Deferred> for BuiltIn<Sqlite>
sqlite only.impl Opens<Deferred> for BuiltIn<Any>
any only.impl Opens<Exclusive> for BuiltIn<Sqlite>
sqlite only.impl Opens<Exclusive> for BuiltIn<Any>
any only.impl Opens<Immediate> for BuiltIn<Sqlite>
sqlite only.impl Opens<Immediate> for BuiltIn<Any>
any only.impl Opens<ReadCommitted> for BuiltIn<Postgres>
postgres only.impl Opens<ReadCommitted> for BuiltIn<MySql>
mysql only.impl Opens<ReadCommitted> for BuiltIn<Any>
any only.impl Opens<ReadUncommitted> for BuiltIn<MySql>
mysql only.impl Opens<ReadUncommitted> for BuiltIn<Any>
any only.impl Opens<RepeatableRead> for BuiltIn<Postgres>
postgres only.impl Opens<RepeatableRead> for BuiltIn<MySql>
mysql only.impl Opens<RepeatableRead> for BuiltIn<Any>
any only.impl Opens<Serializable> for BuiltIn<Postgres>
postgres only.impl Opens<Serializable> for BuiltIn<MySql>
mysql only.impl Opens<Serializable> for BuiltIn<Any>
any only.Source§impl RowLock for BuiltIn<Postgres>
Available on crate feature postgres only.
impl RowLock for BuiltIn<Postgres>
postgres only.Source§fn lock_claim(
&self,
spec: &TableSpec<'_>,
shape: ClaimShape,
) -> Result<Statement, StatementError>
fn lock_claim( &self, spec: &TableSpec<'_>, shape: ClaimShape, ) -> Result<Statement, StatementError>
Param::Limit rows of the
subscription’s group, in claim order, and locks them until the claim’s transaction ends. Read moreSource§impl RowLock for BuiltIn<MySql>
Available on crate feature mysql only.
impl RowLock for BuiltIn<MySql>
mysql only.Source§fn lock_claim(
&self,
spec: &TableSpec<'_>,
shape: ClaimShape,
) -> Result<Statement, StatementError>
fn lock_claim( &self, spec: &TableSpec<'_>, shape: ClaimShape, ) -> Result<Statement, StatementError>
Param::Limit rows of the
subscription’s group, in claim order, and locks them until the claim’s transaction ends. Read moreSource§impl RowLock for BuiltIn<Any>
Available on crate feature any only.
impl RowLock for BuiltIn<Any>
any only.Source§fn lock_claim(
&self,
spec: &TableSpec<'_>,
shape: ClaimShape,
) -> Result<Statement, StatementError>
fn lock_claim( &self, spec: &TableSpec<'_>, shape: ClaimShape, ) -> Result<Statement, StatementError>
Param::Limit rows of the
subscription’s group, in claim order, and locks them until the claim’s transaction ends. Read moreAuto Trait Implementations§
impl<DB> Freeze for BuiltIn<DB>where
<DB as BuiltInDialect>::Picked: Freeze,
impl<DB> RefUnwindSafe for BuiltIn<DB>where
<DB as BuiltInDialect>::Picked: RefUnwindSafe,
impl<DB> Send for BuiltIn<DB>where
<DB as BuiltInDialect>::Picked: Send,
impl<DB> Sync for BuiltIn<DB>where
<DB as BuiltInDialect>::Picked: Sync,
impl<DB> Unpin for BuiltIn<DB>where
<DB as BuiltInDialect>::Picked: Unpin,
impl<DB> UnsafeUnpin for BuiltIn<DB>where
<DB as BuiltInDialect>::Picked: UnsafeUnpin,
impl<DB> UnwindSafe for BuiltIn<DB>where
<DB as BuiltInDialect>::Picked: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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> ⓘ
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