mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-06 17:54:20 +01:00
sqlite3-parser: separate boxed TriggerCmd struct variants
This commit is contained in:
@@ -1651,13 +1651,14 @@ impl ToTokens for TriggerEvent {
|
||||
impl ToTokens for TriggerCmd {
|
||||
fn to_tokens<S: TokenStream>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
match self {
|
||||
Self::Update {
|
||||
or_conflict,
|
||||
tbl_name,
|
||||
sets,
|
||||
from,
|
||||
where_clause,
|
||||
} => {
|
||||
Self::Update(update) => {
|
||||
let TriggerCmdUpdate {
|
||||
or_conflict,
|
||||
tbl_name,
|
||||
sets,
|
||||
from,
|
||||
where_clause,
|
||||
} = &**update;
|
||||
s.append(TK_UPDATE, None)?;
|
||||
if let Some(or_conflict) = or_conflict {
|
||||
s.append(TK_OR, None)?;
|
||||
@@ -1676,14 +1677,15 @@ impl ToTokens for TriggerCmd {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Self::Insert {
|
||||
or_conflict,
|
||||
tbl_name,
|
||||
col_names,
|
||||
select,
|
||||
upsert,
|
||||
returning,
|
||||
} => {
|
||||
Self::Insert(insert) => {
|
||||
let TriggerCmdInsert {
|
||||
or_conflict,
|
||||
tbl_name,
|
||||
col_names,
|
||||
select,
|
||||
upsert,
|
||||
returning,
|
||||
} = &**insert;
|
||||
if let Some(ResolveType::Replace) = or_conflict {
|
||||
s.append(TK_REPLACE, None)?;
|
||||
} else {
|
||||
@@ -1710,14 +1712,11 @@ impl ToTokens for TriggerCmd {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Self::Delete {
|
||||
tbl_name,
|
||||
where_clause,
|
||||
} => {
|
||||
Self::Delete(delete) => {
|
||||
s.append(TK_DELETE, None)?;
|
||||
s.append(TK_FROM, None)?;
|
||||
tbl_name.to_tokens(s)?;
|
||||
if let Some(where_clause) = where_clause {
|
||||
delete.tbl_name.to_tokens(s)?;
|
||||
if let Some(where_clause) = &delete.where_clause {
|
||||
s.append(TK_WHERE, None)?;
|
||||
where_clause.to_tokens(s)?;
|
||||
}
|
||||
|
||||
@@ -1640,44 +1640,56 @@ pub enum TriggerEvent {
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum TriggerCmd {
|
||||
/// `UPDATE`
|
||||
Update {
|
||||
/// `OR`
|
||||
or_conflict: Option<ResolveType>,
|
||||
/// table name
|
||||
tbl_name: Name,
|
||||
/// `SET` assignments
|
||||
sets: Vec<Set>,
|
||||
/// `FROM`
|
||||
from: Option<FromClause>,
|
||||
/// `WHERE` clause
|
||||
where_clause: Option<Expr>,
|
||||
},
|
||||
Update(Box<TriggerCmdUpdate>),
|
||||
/// `INSERT`
|
||||
Insert {
|
||||
/// `OR`
|
||||
or_conflict: Option<ResolveType>,
|
||||
/// table name
|
||||
tbl_name: Name,
|
||||
/// `COLUMNS`
|
||||
col_names: Option<DistinctNames>,
|
||||
/// `SELECT` or `VALUES`
|
||||
select: Box<Select>,
|
||||
/// `ON CONLICT` clause
|
||||
upsert: Option<Upsert>,
|
||||
/// `RETURNING`
|
||||
returning: Option<Vec<ResultColumn>>,
|
||||
},
|
||||
Insert(Box<TriggerCmdInsert>),
|
||||
/// `DELETE`
|
||||
Delete {
|
||||
/// table name
|
||||
tbl_name: Name,
|
||||
/// `WHERE` clause
|
||||
where_clause: Option<Expr>,
|
||||
},
|
||||
Delete(Box<TriggerCmdDelete>),
|
||||
/// `SELECT`
|
||||
Select(Box<Select>),
|
||||
}
|
||||
|
||||
/// `UPDATE` trigger command
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct TriggerCmdUpdate {
|
||||
/// `OR`
|
||||
pub or_conflict: Option<ResolveType>,
|
||||
/// table name
|
||||
pub tbl_name: Name,
|
||||
/// `SET` assignments
|
||||
pub sets: Vec<Set>,
|
||||
/// `FROM`
|
||||
pub from: Option<FromClause>,
|
||||
/// `WHERE` clause
|
||||
pub where_clause: Option<Expr>,
|
||||
}
|
||||
|
||||
/// `INSERT` trigger command
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct TriggerCmdInsert {
|
||||
/// `OR`
|
||||
pub or_conflict: Option<ResolveType>,
|
||||
/// table name
|
||||
pub tbl_name: Name,
|
||||
/// `COLUMNS`
|
||||
pub col_names: Option<DistinctNames>,
|
||||
/// `SELECT` or `VALUES`
|
||||
pub select: Box<Select>,
|
||||
/// `ON CONLICT` clause
|
||||
pub upsert: Option<Upsert>,
|
||||
/// `RETURNING`
|
||||
pub returning: Option<Vec<ResultColumn>>,
|
||||
}
|
||||
|
||||
/// `DELETE` trigger command
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct TriggerCmdDelete {
|
||||
/// table name
|
||||
pub tbl_name: Name,
|
||||
/// `WHERE` clause
|
||||
pub where_clause: Option<Expr>,
|
||||
}
|
||||
|
||||
/// Conflict resolution types
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum ResolveType {
|
||||
|
||||
Reference in New Issue
Block a user