Skip to main content

Form

Enum Form 

Source
#[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<'_>

Source

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§

Source§

impl<'a> Clone for Form<'a>

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<'a> Copy for Form<'a>

Source§

impl<'a> Debug for Form<'a>

Source§

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

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

impl<'a> Default for Form<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> Eq for Form<'a>

Source§

impl<'a> Hash for Form<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for Form<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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