reinhardt_query/types/trigger.rs
1//! Trigger-related types for DDL operations
2
3/// Trigger event type
4///
5/// Specifies which DML operation triggers the trigger execution.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum TriggerEvent {
8 /// INSERT operation
9 Insert,
10 /// UPDATE operation (optionally on specific columns)
11 Update { columns: Option<Vec<String>> },
12 /// DELETE operation
13 Delete,
14}
15
16/// Trigger timing
17///
18/// Specifies when the trigger executes relative to the triggering event.
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum TriggerTiming {
21 /// Execute before the triggering event
22 Before,
23 /// Execute after the triggering event
24 After,
25 /// Execute instead of the triggering event (SQLite views only)
26 InsteadOf,
27}
28
29/// Trigger scope
30///
31/// Specifies whether the trigger executes for each row or once per statement.
32#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33pub enum TriggerScope {
34 /// Execute for each affected row (FOR EACH ROW)
35 Row,
36 /// Execute once per statement (FOR EACH STATEMENT) - PostgreSQL only
37 Statement,
38}
39
40/// Trigger action timing for MySQL
41///
42/// MySQL-specific feature to control trigger execution order.
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub enum TriggerOrder {
45 /// Execute before another trigger
46 Precedes(String),
47 /// Execute after another trigger
48 Follows(String),
49}
50
51/// Trigger body representation
52///
53/// Contains the SQL statements to execute when the trigger fires.
54#[derive(Debug, Clone, PartialEq)]
55pub enum TriggerBody {
56 /// Single SQL statement
57 Single(String),
58 /// Multiple SQL statements (MySQL/SQLite BEGIN...END block)
59 Multiple(Vec<String>),
60 /// PostgreSQL function call (EXECUTE FUNCTION function_name())
61 PostgresFunction(String),
62}
63
64impl TriggerBody {
65 /// Create a single-statement trigger body
66 pub fn single<S: Into<String>>(statement: S) -> Self {
67 Self::Single(statement.into())
68 }
69
70 /// Create a multi-statement trigger body
71 pub fn multiple<I, S>(statements: I) -> Self
72 where
73 I: IntoIterator<Item = S>,
74 S: Into<String>,
75 {
76 Self::Multiple(statements.into_iter().map(|s| s.into()).collect())
77 }
78
79 /// Create a PostgreSQL function call trigger body
80 pub fn postgres_function<S: Into<String>>(function_name: S) -> Self {
81 Self::PostgresFunction(function_name.into())
82 }
83}