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
impl Clone for ClaimShape
impl Copy for ClaimShape
Source§impl Debug for ClaimShape
impl Debug for ClaimShape
impl Eq for ClaimShape
Source§impl Hash for ClaimShape
impl Hash for ClaimShape
Source§impl PartialEq for ClaimShape
impl PartialEq for ClaimShape
impl StructuralPartialEq for ClaimShape
Auto Trait Implementations§
impl Freeze for ClaimShape
impl RefUnwindSafe for ClaimShape
impl Send for ClaimShape
impl Sync for ClaimShape
impl Unpin for ClaimShape
impl UnsafeUnpin for ClaimShape
impl UnwindSafe for ClaimShape
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