#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Statement {
Listen { channel: String },
Unlisten { target: UnlistenTarget },
Set {
scope: SetScope,
parameter: String,
value: SetValue,
},
SetTransaction { options: TransactionOptions },
Reset { target: ResetTarget },
Discard { target: DiscardTarget },
Deallocate { target: DeallocateTarget },
Begin { options: TransactionOptions },
Commit,
Rollback,
Select,
Insert,
Update,
Delete,
Copy,
Other,
}
impl Statement {
pub fn is_read_only(&self) -> bool {
matches!(self, Self::Select)
}
pub fn is_read_write_override(&self) -> bool {
match self {
Self::Begin { options } | Self::SetTransaction { options } => {
options.read_only == Some(false)
}
Self::Set {
parameter, value, ..
} if parameter == "default_transaction_read_only" => match value {
SetValue::Default => true,
SetValue::Literal(s) => crate::sql::as_boolean(s) == Some(false),
},
Self::Reset {
target: ResetTarget::Parameter(name),
} if name == "default_transaction_read_only" => true,
Self::Reset {
target: ResetTarget::All,
} => true,
_ => false,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum UnlistenTarget {
Star,
Channel(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SetScope {
Session,
Local,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SetValue {
Literal(String),
Default,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ResetTarget {
All,
Parameter(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiscardTarget {
All,
Plans,
Sequences,
Temp,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DeallocateTarget {
All,
Name(String),
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct TransactionOptions {
pub read_only: Option<bool>,
}