Skip to main content

BuiltIn

Struct BuiltIn 

Source
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>

Source§

fn advisory_claim( &self, spec: &TableSpec<'_>, ) -> Result<Statement, StatementError>

The candidates: up to 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 more
Source§

fn lock(&self) -> Option<Statement>

Tries the lock on 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 more
Source§

fn unlock(&self) -> Option<Statement>

Releases the lock on 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 more
Source§

fn take( &self, spec: &TableSpec<'_>, shape: ClaimShape, ) -> Result<Vec<Statement>, StatementError>

The statements that take a candidate whose lock the session holds: they count its attempt where the table has one and read the row again in 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 more
Source§

impl ByName<Any> for BuiltIn<Any>

Available on crate feature any only.
Source§

fn headers( value: <Any as Database>::ValueRef<'_>, ) -> Result<HeaderMap, BoxDynError>

The headers a row keeps as a JSON object of strings. Read more
Source§

fn bind_time( arguments: &mut <Any as Database>::Arguments, time: NamedTime, ) -> Result<(), Error>

Binds time: the current time, a delayed retry’s, or a lease’s expiry. Read more
Source§

impl ByName<MySql> for BuiltIn<MySql>

Source§

fn headers( value: <MySql as Database>::ValueRef<'_>, ) -> Result<HeaderMap, BoxDynError>

The headers a row keeps as a JSON object of strings. Read more
Source§

fn bind_time( arguments: &mut <MySql as Database>::Arguments, time: NamedTime, ) -> Result<(), Error>

Binds time: the current time, a delayed retry’s, or a lease’s expiry. Read more
Source§

impl ByName<Postgres> for BuiltIn<Postgres>

Source§

fn headers( value: <Postgres as Database>::ValueRef<'_>, ) -> Result<HeaderMap, BoxDynError>

The headers a row keeps as a JSON object of strings. Read more
Source§

fn bind_time( arguments: &mut <Postgres as Database>::Arguments, time: NamedTime, ) -> Result<(), Error>

Binds time: the current time, a delayed retry’s, or a lease’s expiry. Read more
Source§

impl ByName<Sqlite> for BuiltIn<Sqlite>

Source§

fn headers( value: <Sqlite as Database>::ValueRef<'_>, ) -> Result<HeaderMap, BoxDynError>

The headers a row keeps as a JSON object of strings. Read more
Source§

fn bind_time( arguments: &mut <Sqlite as Database>::Arguments, time: NamedTime, ) -> Result<(), Error>

Binds time: the current time, a delayed retry’s, or a lease’s expiry. Read more
Source§

impl<DB: BuiltInDialect> Clone for BuiltIn<DB>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<DB: BuiltInDialect> Copy for BuiltIn<DB>

Source§

impl<DB: BuiltInDialect> Debug for BuiltIn<DB>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<DB: BuiltInDialect> Dialect for BuiltIn<DB>

Source§

fn name(&self) -> &'static str

The dialect’s name, for messages. Read more
Source§

fn quote_into(&self, ident: &str, out: &mut String)

Appends ident to out, quoted as a name of this database. Read more
Source§

fn placeholder_into(&self, index: NonZeroUsize, out: &mut String)

Appends the placeholder of parameter number index (counted from 1) to out. Read more
Source§

fn fetch(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>

The statement that reads the rows of claimed ids, bound as one list. Read more
Source§

fn ack(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>

The statement that acknowledges a row: it deletes the row, or sets processed_at when the table has that column. Read more
Source§

fn retry( &self, spec: &TableSpec<'_>, ) -> Result<Option<Statement>, StatementError>

The statement that releases a row for another attempt at once, or None when releasing the row needs no statement. Read more
Source§

fn retry_after(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>

The statement that releases a row for another attempt after a delay, bound as Param::RetryAfter. Read more
Source§

fn discard(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>

The statement that drops a row: it deletes the row, or sets processed_at when the table has that column. Read more
Source§

fn dead_letter_group( &self, spec: &TableSpec<'_>, ) -> Result<Statement, StatementError>

The statement that moves a row whose attempts are spent to another group, bound as Param::Destination. Read more
Source§

fn dead_letter_table( &self, spec: &TableSpec<'_>, target: TableName<'_>, ) -> Result<Vec<Statement>, StatementError>

The statements that move a row whose attempts are spent to target, a table with the same columns; they run in one transaction. Read more
Source§

fn insert(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>

The statement that inserts a row: every column the database does not fill, in the order of TableSpec::columns, each bound as Param::Column. Read more
Source§

fn server_version(&self) -> Option<&'static str>

The query that reads the server’s version as one text column, or None when the dialect’s statements run on every version of its server. Read more
Source§

fn check_server( &self, spec: &TableSpec<'_>, version: &str, ) -> Result<(), StatementError>

Refuses a server older than the statements of spec need; version is what the server_version query returned. Read more
Source§

fn begin( &self, opening: Opening, ) -> Result<Option<&'static str>, StatementError>

The statement that opens a transaction at opening in place of BEGIN, or None when BEGIN opens it. Read more
Source§

fn savepoint(&self) -> &'static str

The statement that sets the savepoint after a claim, inside the claim’s transaction: what a handler writes after it can be discarded while the claim’s own work stays. Read more
Source§

fn rollback_to_savepoint(&self) -> &'static str

The statement that discards what the transaction did after savepoint, and keeps the transaction open. Read more
Source§

fn fifo_guard( &self, spec: &TableSpec<'_>, ) -> Result<Option<Statement>, StatementError>

The statement a claim of a table with FIFO groups runs first in its transaction, to take the subscription’s group for it; None for a table without FIFO groups, or a dialect that takes no group. Read more
Source§

impl<DB: BuiltInDialect> Lease for BuiltIn<DB>

Source§

fn lease_claim( &self, spec: &TableSpec<'_>, shape: ClaimShape, ) -> Result<Statement, StatementError>

The statement that claims up to Param::Limit rows of the subscription’s group, in claim order, among the rows whose lease ended by Param::LeaseNow. Read more
Source§

fn extend(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>

The statement that extends a delivery’s lease: it writes the new expiry (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 more
Source§

fn stamp(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError>

The statement that leases one claimed row: it writes the expiry (Param::Lease) and counts the attempt, while no lease holds the row at Param::LeaseNow. Read more
Source§

fn claim_writes_lease(&self) -> bool

Whether the lease claim writes the lease itself. A dialect whose lease claim only selects the rows answers false, and the claim’s transaction then runs stamp for each claimed row before it commits. Read more
Source§

fn claim_counts_attempt(&self, spec: &TableSpec<'_>) -> bool

Whether the rows the lease claim of 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 more
Source§

fn begin_lease_claim(&self) -> Option<&'static str>

The statement that opens the transaction of a claim that only selects its rows, in place of BEGIN, or None when BEGIN opens it. Read more
Source§

impl Opens<Deferred> for BuiltIn<Sqlite>

Available on crate feature sqlite only.
Source§

impl Opens<Deferred> for BuiltIn<Any>

Available on crate feature any only.
Source§

impl Opens<Exclusive> for BuiltIn<Sqlite>

Available on crate feature sqlite only.
Source§

impl Opens<Exclusive> for BuiltIn<Any>

Available on crate feature any only.
Source§

impl Opens<Immediate> for BuiltIn<Sqlite>

Available on crate feature sqlite only.
Source§

impl Opens<Immediate> for BuiltIn<Any>

Available on crate feature any only.
Source§

impl Opens<ReadCommitted> for BuiltIn<Postgres>

Available on crate feature postgres only.
Source§

impl Opens<ReadCommitted> for BuiltIn<MySql>

Available on crate feature mysql only.
Source§

impl Opens<ReadCommitted> for BuiltIn<Any>

Available on crate feature any only.
Source§

impl Opens<ReadUncommitted> for BuiltIn<MySql>

Available on crate feature mysql only.
Source§

impl Opens<ReadUncommitted> for BuiltIn<Any>

Available on crate feature any only.
Source§

impl Opens<RepeatableRead> for BuiltIn<Postgres>

Available on crate feature postgres only.
Source§

impl Opens<RepeatableRead> for BuiltIn<MySql>

Available on crate feature mysql only.
Source§

impl Opens<RepeatableRead> for BuiltIn<Any>

Available on crate feature any only.
Source§

impl Opens<Serializable> for BuiltIn<Postgres>

Available on crate feature postgres only.
Source§

impl Opens<Serializable> for BuiltIn<MySql>

Available on crate feature mysql only.
Source§

impl Opens<Serializable> for BuiltIn<Any>

Available on crate feature any only.
Source§

impl RowLock for BuiltIn<Postgres>

Available on crate feature postgres only.
Source§

fn lock_claim( &self, spec: &TableSpec<'_>, shape: ClaimShape, ) -> Result<Statement, StatementError>

The statement that claims up to Param::Limit rows of the subscription’s group, in claim order, and locks them until the claim’s transaction ends. Read more
Source§

impl RowLock for BuiltIn<MySql>

Available on crate feature mysql only.
Source§

fn lock_claim( &self, spec: &TableSpec<'_>, shape: ClaimShape, ) -> Result<Statement, StatementError>

The statement that claims up to Param::Limit rows of the subscription’s group, in claim order, and locks them until the claim’s transaction ends. Read more
Source§

impl RowLock for BuiltIn<Any>

Available on crate feature any only.
Source§

fn lock_claim( &self, spec: &TableSpec<'_>, shape: ClaimShape, ) -> Result<Statement, StatementError>

The statement that claims up to Param::Limit rows of the subscription’s group, in claim order, and locks them until the claim’s transaction ends. Read more

Auto 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> 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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

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

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

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
Source§

impl<D> Opens<()> for D
where D: Dialect,

Source§

impl<T> PublishedThrough<DefaultSlot> for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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