Struct rorm_sql::create_trigger::SQLCreateTrigger
source · pub struct SQLCreateTrigger { /* private fields */ }Expand description
Representation of a trigger.
Implementations§
source§impl SQLCreateTrigger
impl SQLCreateTrigger
sourcepub fn if_not_exists(self) -> Self
pub fn if_not_exists(self) -> Self
Create the trigger only, if it does not exists
Examples found in repository?
src/create_trigger.rs (line 137)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
pub(crate) fn trigger_annotation_to_trigger_sqlite(
annotation: &Annotation,
db_type: &DbType,
table_name: &str,
column_name: &str,
statements: &mut Vec<(String, Vec<Value>)>,
) {
if annotation == &Annotation::AutoUpdateTime {
let update_statement = format!(
"UPDATE {} SET {} = {} WHERE ROWID = NEW.ROWID;",
table_name,
column_name,
match db_type {
DbType::Date => "CURRENT_DATE",
DbType::DateTime => "CURRENT_TIMESTAMP",
DbType::Timestamp => "CURRENT_TIMESTAMP",
DbType::Time => "CURRENT_TIME",
_ => "",
}
);
statements.push((
DBImpl::SQLite
.create_trigger(
format!("{}_{}_auto_update_time", table_name, column_name).as_str(),
table_name,
Some(SQLCreateTriggerPointInTime::After),
SQLCreateTriggerOperation::Update { columns: None },
)
.for_each_row()
.if_not_exists()
.add_statement(update_statement)
.build(),
vec![],
))
}
}sourcepub fn add_statement(self, statement: String) -> Self
pub fn add_statement(self, statement: String) -> Self
Adds a statement to a create trigger operation
Examples found in repository?
src/create_trigger.rs (line 138)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
pub(crate) fn trigger_annotation_to_trigger_sqlite(
annotation: &Annotation,
db_type: &DbType,
table_name: &str,
column_name: &str,
statements: &mut Vec<(String, Vec<Value>)>,
) {
if annotation == &Annotation::AutoUpdateTime {
let update_statement = format!(
"UPDATE {} SET {} = {} WHERE ROWID = NEW.ROWID;",
table_name,
column_name,
match db_type {
DbType::Date => "CURRENT_DATE",
DbType::DateTime => "CURRENT_TIMESTAMP",
DbType::Timestamp => "CURRENT_TIMESTAMP",
DbType::Time => "CURRENT_TIME",
_ => "",
}
);
statements.push((
DBImpl::SQLite
.create_trigger(
format!("{}_{}_auto_update_time", table_name, column_name).as_str(),
table_name,
Some(SQLCreateTriggerPointInTime::After),
SQLCreateTriggerOperation::Update { columns: None },
)
.for_each_row()
.if_not_exists()
.add_statement(update_statement)
.build(),
vec![],
))
}
}sourcepub fn for_each_row(self) -> Self
pub fn for_each_row(self) -> Self
Executes the given trigger statement for each row individually.
Examples found in repository?
src/create_trigger.rs (line 136)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
pub(crate) fn trigger_annotation_to_trigger_sqlite(
annotation: &Annotation,
db_type: &DbType,
table_name: &str,
column_name: &str,
statements: &mut Vec<(String, Vec<Value>)>,
) {
if annotation == &Annotation::AutoUpdateTime {
let update_statement = format!(
"UPDATE {} SET {} = {} WHERE ROWID = NEW.ROWID;",
table_name,
column_name,
match db_type {
DbType::Date => "CURRENT_DATE",
DbType::DateTime => "CURRENT_TIMESTAMP",
DbType::Timestamp => "CURRENT_TIMESTAMP",
DbType::Time => "CURRENT_TIME",
_ => "",
}
);
statements.push((
DBImpl::SQLite
.create_trigger(
format!("{}_{}_auto_update_time", table_name, column_name).as_str(),
table_name,
Some(SQLCreateTriggerPointInTime::After),
SQLCreateTriggerOperation::Update { columns: None },
)
.for_each_row()
.if_not_exists()
.add_statement(update_statement)
.build(),
vec![],
))
}
}sourcepub fn build(self) -> String
pub fn build(self) -> String
Generate the resulting SQL string
Examples found in repository?
src/create_trigger.rs (line 139)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
pub(crate) fn trigger_annotation_to_trigger_sqlite(
annotation: &Annotation,
db_type: &DbType,
table_name: &str,
column_name: &str,
statements: &mut Vec<(String, Vec<Value>)>,
) {
if annotation == &Annotation::AutoUpdateTime {
let update_statement = format!(
"UPDATE {} SET {} = {} WHERE ROWID = NEW.ROWID;",
table_name,
column_name,
match db_type {
DbType::Date => "CURRENT_DATE",
DbType::DateTime => "CURRENT_TIMESTAMP",
DbType::Timestamp => "CURRENT_TIMESTAMP",
DbType::Time => "CURRENT_TIME",
_ => "",
}
);
statements.push((
DBImpl::SQLite
.create_trigger(
format!("{}_{}_auto_update_time", table_name, column_name).as_str(),
table_name,
Some(SQLCreateTriggerPointInTime::After),
SQLCreateTriggerOperation::Update { columns: None },
)
.for_each_row()
.if_not_exists()
.add_statement(update_statement)
.build(),
vec![],
))
}
}