Skip to main content

ClaimShape

Enum ClaimShape 

Source
pub enum ClaimShape {
    Rows,
    Ids,
    Roles,
}
Expand description

What a claim selects: whole rows, only their ids for a service’s own fetch, or the columns that run the queue, each named by its role, for a reader that knows no struct.

§Examples

A claim of a dialect of the service’s own selects what the shape asks for:

use ruststream_sqlx_dialect::{
    ClaimShape, Dialect, Param, Role, RowLock, Statement, StatementError, TableSpec,
};

/// SQL Server, a database without a built-in dialect.
#[derive(Debug)]
pub struct Mssql;

impl RowLock for Mssql {
    // The service's queue tables have no groups and no claim order of their own.
    fn lock_claim(
        &self,
        spec: &TableSpec<'_>,
        shape: ClaimShape,
    ) -> Result<Statement, StatementError> {
        let mut selected = String::new();
        match shape {
            // Whole rows, for a struct the broker reads.
            ClaimShape::Rows => {
                for column in spec.columns() {
                    if !selected.is_empty() {
                        selected.push_str(", ");
                    }
                    self.quote_into(column.name(), &mut selected);
                }
            }
            // Only the ids, for a struct that fetches its rows itself.
            ClaimShape::Ids => self.quote_into(spec.id().name(), &mut selected),
            // The columns that run the queue, each under the name of its role.
            ClaimShape::Roles => {
                let roles = [
                    Role::Id,
                    Role::PartitionKey,
                    Role::Attempt,
                    Role::Headers,
                    Role::Payload,
                ];
                for role in roles {
                    let Some(column) = spec.column(role) else {
                        continue;
                    };
                    if !selected.is_empty() {
                        selected.push_str(", ");
                    }
                    self.quote_into(column.name(), &mut selected);
                    selected.push_str(" AS ");
                    self.quote_into(role.attribute(), &mut selected);
                }
            }
        }
        let mut sql = format!("SELECT TOP (@p1) {selected} FROM ");
        self.quote_into(spec.table(), &mut sql);
        sql.push_str(" WITH (UPDLOCK, READPAST) ORDER BY ");
        self.quote_into(spec.id().name(), &mut sql);
        Ok(Statement::new(sql, [Param::Limit]))
    }
}

Variants§

§

Rows

Every column of the claimed rows.

§

Ids

Only the id of each claimed row.

§

Roles

Only the columns that play id, partition_key, attempt, headers and payload, each under its role’s attribute name as an alias, in Role::ALL order.

Trait Implementations§

Source§

impl Clone for ClaimShape

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 Copy for ClaimShape

Source§

impl Debug for ClaimShape

Source§

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

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

impl Eq for ClaimShape

Source§

impl Hash for ClaimShape

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 PartialEq for ClaimShape

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 StructuralPartialEq for ClaimShape

Auto Trait Implementations§

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.