Skip to content

Commit b57c1c2

Browse files
committed
chore: expression ast refactoring
1 parent cad43d5 commit b57c1c2

17 files changed

+691
-631
lines changed

src/ast/alter.rs

+27
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ pub enum FKAction {
184184
NoAction,
185185
}
186186

187+
impl Display for FKAction {
188+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
189+
match self {
190+
FKAction::SetDefault => write!(f, "SET DEFAULT"),
191+
FKAction::SetNull => write!(f, "SET NULL"),
192+
FKAction::Cascade => write!(f, "CASCADE"),
193+
FKAction::Restrict => write!(f, "RESTRICT"),
194+
FKAction::NoAction => write!(f, "NO ACTION"),
195+
}
196+
}
197+
}
198+
187199
/// A [Deferrable](https://www.sqlite.org/syntax/foreign-key-clause.html)
188200
/// clause in a ForeignKeyConstraint
189201
#[derive(Debug, PartialEq, Clone)]
@@ -194,6 +206,21 @@ pub enum FKDeferrableType {
194206
Not(Box<FKDeferrableType>),
195207
}
196208

209+
impl Display for FKDeferrableType {
210+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
211+
match self {
212+
FKDeferrableType::Deferrable => write!(f, "DEFERRABLE"),
213+
FKDeferrableType::Not(deferrable_type) => write!(f, "NOT {}", deferrable_type),
214+
FKDeferrableType::InitiallyDeferred => {
215+
write!(f, "DEFERRABLE INITIALLY DEFERRED")
216+
}
217+
FKDeferrableType::InitiallyImmediate => {
218+
write!(f, "DEFERRABLE INITIALLY IMMEDIATE")
219+
}
220+
}
221+
}
222+
}
223+
197224
/// A GeneratedColumnConstraint, used in ALTER TABLE ADD COLUMN statement
198225
#[derive(Debug, PartialEq, Clone)]
199226
pub struct GeneratedColumnConstraint {

src/ast/create.rs

+21
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,27 @@ pub enum TriggerEventType {
164164
Update(Option<Vec<Identifier>>),
165165
}
166166

167+
impl Display for TriggerEventType {
168+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
169+
match self {
170+
TriggerEventType::Delete => write!(f, "DELETE"),
171+
TriggerEventType::Insert => write!(f, "INSERT"),
172+
TriggerEventType::Update(columns) => match columns {
173+
Some(columns) => write!(
174+
f,
175+
"UPDATE OF {}",
176+
columns
177+
.iter()
178+
.map(|c| c.to_string())
179+
.collect::<Vec<String>>()
180+
.join(", ")
181+
),
182+
None => write!(f, "UPDATE"),
183+
},
184+
}
185+
}
186+
}
187+
167188
#[derive(Debug, PartialEq, Clone)]
168189
pub enum TriggerStatement {
169190
Update(UpdateStatement),

0 commit comments

Comments
 (0)