#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WriteObservation {
pub name: String,
pub table: String,
pub event: ObservationEvent,
pub when: GuardPredicate,
pub target_table: String,
pub columns: Vec<ObservationColumn>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ObservationEvent {
AfterInsert,
AfterUpdate,
AfterDelete,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ObservationColumn {
pub column: String,
pub value: GuardValue,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WriteGuard {
pub name: String,
pub table: String,
pub event: GuardEvent,
pub reject_when: GuardPredicate,
pub violation: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GuardEvent {
BeforeInsert,
BeforeUpdate,
BeforeDelete,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GuardScalar {
Null,
Integer(i64),
Text(String),
Bool(bool),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ObservationLookupKey {
NewColumn(String),
OldColumn(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UniqueScalarLookup {
pub table: String,
pub key_column: String,
pub key: ObservationLookupKey,
pub value_column: String,
pub max_bytes: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GuardValue {
UniqueScalarLookup(UniqueScalarLookup),
UniqueScalarLookupStatus(UniqueScalarLookup),
NewColumn(String),
OldColumn(String),
Column {
relation: String,
column: String,
},
Constant(GuardScalar),
BoundedText {
value: Box<Self>,
max_bytes: u32,
},
BoundedTextStatus {
value: Box<Self>,
max_bytes: u32,
},
IntegerOnly {
value: Box<Self>,
},
IntegerStatus {
value: Box<Self>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GuardPredicate {
Equal(GuardValue, GuardValue),
NotEqual(GuardValue, GuardValue),
IsNull(GuardValue),
IsNotNull(GuardValue),
ByteLengthAtMost(GuardValue, u32),
InValues(GuardValue, Vec<GuardScalar>),
All(Vec<Self>),
Any(Vec<Self>),
Exists(GuardRelation),
NotExists(GuardRelation),
Not(Box<Self>),
IntegerSuccessor {
previous: GuardValue,
next: GuardValue,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GuardRelation {
pub table: String,
pub alias: String,
pub joins: Vec<GuardJoin>,
pub predicate: Box<GuardPredicate>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GuardJoin {
pub table: String,
pub alias: String,
pub left: GuardValue,
pub right: GuardValue,
}