#[derive(Debug, Clone)]
pub enum StorageOp {
BatchUpsert(UpsertSpec),
MonotonicUpsert(MonotonicUpsertSpec),
BatchUpdate(BatchUpdateSpec),
GuardedBump(GuardedBumpSpec),
ScopedGuardedBump(ScopedGuardedBumpSpec),
Get(GetSpec),
ScopedGet(ScopedGetSpec),
ScopedMax(ScopedMaxSpec),
ScopedScan(ScopedScanSpec),
Scan(ScanSpec),
BatchDelete(BatchDeleteSpec),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SparseTableSpec {
pub table: &'static str,
pub identity_cols: &'static [&'static str],
pub scope_col: Option<&'static str>,
}
#[derive(Debug, Clone)]
pub struct UpsertSpec {
pub table: &'static str,
pub rows: Vec<Row>,
pub conflict_key: Option<&'static str>,
pub exclude_from_update: Vec<&'static str>,
pub update_guard: Option<UpsertGuard>,
pub version_column: Option<&'static str>,
}
#[derive(Debug, Clone)]
pub struct UpsertGuard {
pub column: &'static str,
pub expected: SqlValue,
}
impl UpsertSpec {
pub fn new(table: &'static str, rows: Vec<Row>, conflict_key: Option<&'static str>) -> Self {
Self {
table,
rows,
conflict_key,
exclude_from_update: Vec::new(),
version_column: None,
update_guard: None,
}
}
}
#[derive(Debug, Clone)]
pub struct MonotonicUpsertSpec {
pub table: &'static str,
pub key_col: &'static str,
pub value_col: &'static str,
pub touch_col: Option<&'static str>,
pub scope_key: String,
pub value: i64,
}
#[derive(Debug, Clone)]
pub struct BatchUpdateSpec {
pub table: &'static str,
pub key_col: &'static str,
pub key_vals: Vec<SqlValue>,
pub patch: Row,
}
#[derive(Debug, Clone)]
pub struct BatchDeleteSpec {
pub table: &'static str,
pub scope_col: &'static str,
pub scope_val: SqlValue,
pub key_col: &'static str,
pub key_vals: Vec<SqlValue>,
}
#[derive(Debug, Clone)]
pub struct GuardedBumpSpec {
pub table: &'static str,
pub key_col: &'static str,
pub key_val: SqlValue,
pub bump_col: &'static str,
pub bump_delta: i64,
pub extra_bumps: Vec<(&'static str, i64)>,
pub set_cols: Row,
pub guard_col: &'static str,
pub guard_val: i64,
}
#[derive(Debug, Clone)]
pub struct ScopedGuardedBumpSpec {
pub table: &'static str,
pub scope_col: &'static str,
pub scope_val: SqlValue,
pub key_col: &'static str,
pub key_val: SqlValue,
pub bump_col: &'static str,
pub bump_delta: i64,
pub set_cols: Row,
pub guard_col: &'static str,
pub guard_val: i64,
pub additional_guard: Option<(&'static str, SqlValue)>,
}
#[derive(Debug, Clone)]
pub struct GetSpec {
pub table: &'static str,
pub key_col: &'static str,
pub key_val: SqlValue,
}
#[derive(Debug, Clone)]
pub struct ScopedGetSpec {
pub table: &'static str,
pub scope_col: &'static str,
pub scope_val: SqlValue,
pub key_col: &'static str,
pub key_val: SqlValue,
}
#[derive(Debug, Clone)]
pub struct ScopedMaxSpec {
pub table: &'static str,
pub scope_col: &'static str,
pub scope_values: Vec<SqlValue>,
pub value_col: &'static str,
pub result_alias: &'static str,
}
#[derive(Debug, Clone)]
pub struct ScopedScanSpec {
pub table: &'static str,
pub scope_col: &'static str,
pub scope_values: Vec<SqlValue>,
pub limit: usize,
}
#[derive(Debug, Clone)]
pub struct ScanSpec {
pub table: &'static str,
pub limit: Option<u32>,
pub filter: Option<(&'static str, SqlValue)>,
pub order_by: &'static [ScanOrder],
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SortDirection {
Asc,
Desc,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ScanOrder {
pub column: &'static str,
pub direction: SortDirection,
}
impl ScanOrder {
pub const fn asc(column: &'static str) -> Self {
Self {
column,
direction: SortDirection::Asc,
}
}
pub const fn desc(column: &'static str) -> Self {
Self {
column,
direction: SortDirection::Desc,
}
}
}
#[derive(Debug, Clone)]
pub enum SqlValue {
Text(String),
Integer(i64),
Real(f64),
Blob(Vec<u8>),
Null,
}
pub type Row = Vec<(String, SqlValue)>;