-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Triggers #824
base: master
Are you sure you want to change the base?
Triggers #824
Conversation
self.prepare_table_ref_iden(&trigger_ref, sql); | ||
write!(sql, " {} {} ON ", create.trigger.time, create.trigger.event).unwrap(); | ||
self.prepare_table_ref_iden(&create.trigger.table, sql); | ||
write!(sql, " FOR EACH ROW\nBEGIN\n").unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have statement level triggers although they aren't available in mysql.
pub type TriggerActions = Vec<TriggerAction>; | ||
|
||
#[derive(Default, Debug, Clone)] | ||
pub struct NamedTrigger { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about unifying the two into one with fn named(...)
and fn unnamed(...)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two structs UnnamedTrigger
and NamedTrigger
are distinguished because of slightly different interfaces. Generating trigger names is only needed when a user did not specify an explicit name. Differentiating structs within the Trigger enum allows auto-completion.
The Trigger implementation has two methods new
and with_name
that are similar to your suggestion:
impl Trigger {
pub fn new() -> Trigger {
Trigger::UnnamedTrigger(None, None, None)
}
pub fn with_name(name: TriggerRef) -> Trigger {
Trigger::NamedTrigger(name, None, None, None)
}
}
@HigherOrderLogic do you think we should get rid of the two variants and accept that users might inadvertently use unnamed triggers? Typically I prefer being explicit, but I also see the potential to reduce complexity. Happy to hear your suggestion. 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think we should get rid of the two variants and accept that users might inadvertently use unnamed triggers
I think that an unified enum would be better for end users DX, however, I disagree that unnamed should be the default.
As I stated in the previous comment, we can implement different functions for each variants, eg:
impl Trigger {
pub fn unnamed() -> Trigger {
Trigger::UnnamedTrigger(None, None, None)
}
pub fn named(name: TriggerRef) -> Trigger {
Trigger::NamedTrigger(name, None, None, None)
}
}
Issue #403 discusses ideas and interfaces to implement SQL triggers. Inspired by this conversation, this pull-request suggests a way to implement triggers.
This PR is in an early stage and meant to provide surface for discussion and tinkering.
The action expression (between BEGIN and END) does not make sense yet and exists to outline the idea. With new features to express logic, variable declaration, loops and custom errors this could be achieved though.
New Features
TBD
CKECK
constraints for MySQL and SqliteIF NOT EXISTS
differences between database backends + write unit-tests