pub trait BuiltInDialect: QueueDatabase {
// Required method
fn dialect(conn: &Self::Connection) -> Option<BuiltIn<Self>>;
}Expand description
A database whose dialect is built into this crate, so SqlxBroker::new needs no dialect of
the service’s own.
Postgres (feature postgres), MySQL with MariaDB (feature mysql) and SQLite (feature
sqlite) have one, BuiltIn<DB>. Any (feature any) takes the dialect of the
database its pool reaches, among those whose features are on, and the broker picks it when it
connects. A row on an AnyPool holds only the types sqlx::Any carries, and no time is among
them, so a table with locked_until, retry_after or processed_at is out of its reach.
§Examples
use ruststream_sqlx::prelude::*;
use serde::Deserialize;
use sqlx::AnyPool;
// The columns `sqlx::Any` carries: integers, text and bytes, no time.
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "email_jobs")]
pub struct SendEmail {
#[field(id, generated)]
job_id: i64,
#[field(group)]
name: String,
#[field(attempt, generated)]
attempt: i32,
#[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()
}
// One build for every deployment: `Any` is a `BuiltInDialect`, and the broker takes the
// dialect of the database the URL names, Postgres or MySQL, when it connects. `main` installs
// sqlx's drivers (`sqlx::any::install_default_drivers`) before it builds the pool.
pub fn app(pool: AnyPool) -> RustStream {
RustStream::new(AppInfo::new("mailer", "0.1.0")).with_broker(SqlxBroker::new(pool), |b| {
b.include(send);
})
}Required Methods§
Sourcefn dialect(conn: &Self::Connection) -> Option<BuiltIn<Self>>
fn dialect(conn: &Self::Connection) -> Option<BuiltIn<Self>>
The dialect that builds the statements of the database conn reaches, or None when no
built-in dialect serves it: an AnyPool’s backend whose feature is off.
Postgres, MySQL and SQLite answer without reading conn; the broker asks with the
connection it checks when it connects.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl BuiltInDialect for Any
Available on crate feature any only.
impl BuiltInDialect for Any
any only.Source§impl BuiltInDialect for MySql
Available on crate feature mysql only.
impl BuiltInDialect for MySql
mysql only.Source§impl BuiltInDialect for Postgres
Available on crate feature postgres only.
impl BuiltInDialect for Postgres
postgres only.Source§impl BuiltInDialect for Sqlite
Available on crate feature sqlite only.
impl BuiltInDialect for Sqlite
sqlite only.