#[non_exhaustive]pub enum Form<'a> {
RowLock,
Lease(Column<'a>),
Advisory(&'a [KeyPart<'a>]),
}Expand description
How a subscription claims the rows of a table; a table has exactly one form.
The lease form carries its locked_until column and the advisory form its key, so a table
cannot declare two forms. The row lock is the default: the form of a table that declares
neither.
§Examples
A settlement of a dialect of the service’s own follows the form:
use ruststream_sqlx_dialect::{Dialect, Form, Param, Statement, StatementError, TableSpec};
/// SQL Server, a database without a built-in dialect.
#[derive(Debug)]
pub struct Mssql;
impl Dialect for Mssql {
fn name(&self) -> &'static str {
"mssql"
}
fn ack(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError> {
let mut sql = String::from("DELETE FROM ");
self.quote_into(spec.table(), &mut sql);
sql.push_str(" WHERE ");
self.quote_into(spec.id().name(), &mut sql);
sql.push_str(" = @p1");
match spec.form() {
// In the lease form the row goes only while it holds the delivery's lease.
Form::Lease(expiry) => {
sql.push_str(" AND ");
self.quote_into(expiry.name(), &mut sql);
sql.push_str(" = @p2");
Ok(Statement::new(sql, [Param::Id, Param::Held]))
}
_ => Ok(Statement::new(sql, [Param::Id])),
}
}
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
RowLock
Rows stay locked in a transaction held for the whole handler; the default.
Lease(Column<'a>)
A claim sets this column, the lease’s expiry, and commits; the value holds the row.
Advisory(&'a [KeyPart<'a>])
A session lock on the key these parts build from the row holds the row.
Implementations§
Source§impl Form<'_>
impl Form<'_>
Sourcepub const fn name(&self) -> &'static str
pub const fn name(&self) -> &'static str
The form’s name in messages: row lock, lease or advisory lock.
§Examples
use ruststream_sqlx_dialect::{Dialect, Form, Param, Statement, StatementError, TableSpec};
/// SQL Server, a database without a built-in dialect.
#[derive(Debug)]
pub struct Mssql;
impl Dialect for Mssql {
fn name(&self) -> &'static str {
"mssql"
}
fn ack(&self, spec: &TableSpec<'_>) -> Result<Statement, StatementError> {
// This dialect serves the row lock form alone, and its refusal names the table's
// form.
if spec.form() != Form::RowLock {
return Err(StatementError::UnsupportedForm {
dialect: self.name(),
form: spec.form().name(),
});
}
let mut sql = String::from("DELETE FROM ");
self.quote_into(spec.table(), &mut sql);
sql.push_str(" WHERE ");
self.quote_into(spec.id().name(), &mut sql);
sql.push_str(" = @p1");
Ok(Statement::new(sql, [Param::Id]))
}
}Trait Implementations§
impl<'a> Copy for Form<'a>
impl<'a> Eq for Form<'a>
impl<'a> StructuralPartialEq for Form<'a>
Auto Trait Implementations§
impl<'a> Freeze for Form<'a>
impl<'a> RefUnwindSafe for Form<'a>
impl<'a> Send for Form<'a>
impl<'a> Sync for Form<'a>
impl<'a> Unpin for Form<'a>
impl<'a> UnsafeUnpin for Form<'a>
impl<'a> UnwindSafe for Form<'a>
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
Mutably borrows from an owned value. Read more