mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-06 01:34:21 +01:00
sqlite3-parser: separate boxed CreateTrigger struct
This commit is contained in:
@@ -211,17 +211,18 @@ impl ToTokens for Stmt {
|
||||
tbl_name.to_tokens(s)?;
|
||||
body.to_tokens(s)
|
||||
}
|
||||
Self::CreateTrigger {
|
||||
temporary,
|
||||
if_not_exists,
|
||||
trigger_name,
|
||||
time,
|
||||
event,
|
||||
tbl_name,
|
||||
for_each_row,
|
||||
when_clause,
|
||||
commands,
|
||||
} => {
|
||||
Self::CreateTrigger(trigger) => {
|
||||
let CreateTrigger {
|
||||
temporary,
|
||||
if_not_exists,
|
||||
trigger_name,
|
||||
time,
|
||||
event,
|
||||
tbl_name,
|
||||
for_each_row,
|
||||
when_clause,
|
||||
commands,
|
||||
} = &**trigger;
|
||||
s.append(TK_CREATE, None)?;
|
||||
if *temporary {
|
||||
s.append(TK_TEMP, None)?;
|
||||
|
||||
@@ -115,26 +115,7 @@ pub enum Stmt {
|
||||
body: Box<CreateTableBody>,
|
||||
},
|
||||
/// `CREATE TRIGGER`
|
||||
CreateTrigger {
|
||||
/// `TEMPORARY`
|
||||
temporary: bool,
|
||||
/// `IF NOT EXISTS`
|
||||
if_not_exists: bool,
|
||||
/// trigger name
|
||||
trigger_name: QualifiedName,
|
||||
/// `BEFORE`/`AFTER`/`INSTEAD OF`
|
||||
time: Option<TriggerTime>,
|
||||
/// `DELETE`/`INSERT`/`UPDATE`
|
||||
event: Box<TriggerEvent>,
|
||||
/// table name
|
||||
tbl_name: QualifiedName,
|
||||
/// `FOR EACH ROW`
|
||||
for_each_row: bool,
|
||||
/// `WHEN`
|
||||
when_clause: Option<Box<Expr>>,
|
||||
/// statements
|
||||
commands: Vec<TriggerCmd>,
|
||||
},
|
||||
CreateTrigger(Box<CreateTrigger>),
|
||||
/// `CREATE VIEW`
|
||||
CreateView {
|
||||
/// `TEMPORARY`
|
||||
@@ -242,30 +223,28 @@ pub enum Stmt {
|
||||
/// `SELECT`
|
||||
Select(Box<Select>),
|
||||
/// `UPDATE`
|
||||
Update {
|
||||
/// CTE
|
||||
with: Option<With>,
|
||||
/// `OR`
|
||||
or_conflict: Option<ResolveType>,
|
||||
/// table name
|
||||
tbl_name: QualifiedName,
|
||||
/// `INDEXED`
|
||||
indexed: Option<Indexed>,
|
||||
/// `SET` assignments
|
||||
sets: Vec<Set>,
|
||||
/// `FROM`
|
||||
from: Option<FromClause>,
|
||||
/// `WHERE` clause
|
||||
where_clause: Option<Box<Expr>>,
|
||||
/// `RETURNING`
|
||||
returning: Option<Vec<ResultColumn>>,
|
||||
/// `ORDER BY`
|
||||
order_by: Option<Vec<SortedColumn>>,
|
||||
/// `LIMIT`
|
||||
limit: Option<Box<Limit>>,
|
||||
},
|
||||
/// `VACUUM`: database name, into expr
|
||||
Vacuum(Option<Name>, Option<Expr>),
|
||||
/// `CREATE TRIGGER
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CreateTrigger {
|
||||
/// `TEMPORARY`
|
||||
pub temporary: bool,
|
||||
/// `IF NOT EXISTS`
|
||||
pub if_not_exists: bool,
|
||||
/// trigger name
|
||||
pub trigger_name: QualifiedName,
|
||||
/// `BEFORE`/`AFTER`/`INSTEAD OF`
|
||||
pub time: Option<TriggerTime>,
|
||||
/// `DELETE`/`INSERT`/`UPDATE`
|
||||
pub event: TriggerEvent,
|
||||
/// table name
|
||||
pub tbl_name: QualifiedName,
|
||||
/// `FOR EACH ROW`
|
||||
pub for_each_row: bool,
|
||||
/// `WHEN`
|
||||
pub when_clause: Option<Expr>,
|
||||
/// statements
|
||||
pub commands: Vec<TriggerCmd>,
|
||||
}
|
||||
}
|
||||
|
||||
/// SQL expression
|
||||
|
||||
@@ -1166,10 +1166,10 @@ minus_num(A) ::= MINUS number(X). {A = Expr::unary(UnaryOperator::Negative,
|
||||
|
||||
cmd ::= createkw temp(T) TRIGGER ifnotexists(NOERR) fullname(B) trigger_time(C) trigger_event(D)
|
||||
ON fullname(E) foreach_clause(X) when_clause(G) BEGIN trigger_cmd_list(S) END. {
|
||||
self.ctx.stmt = Some(Stmt::CreateTrigger{
|
||||
temporary: T, if_not_exists: NOERR, trigger_name: B, time: C, event: Box::new(D), tbl_name: E,
|
||||
for_each_row: X, when_clause: G.map(Box::new), commands: S
|
||||
});
|
||||
self.ctx.stmt = Some(Stmt::CreateTrigger(Box::new(CreateTrigger{
|
||||
temporary: T, if_not_exists: NOERR, trigger_name: B, time: C, event: D, tbl_name: E,
|
||||
for_each_row: X, when_clause: G, commands: S
|
||||
})));
|
||||
}
|
||||
|
||||
%type trigger_time {Option<TriggerTime>}
|
||||
|
||||
Reference in New Issue
Block a user