pub struct SQLCreateTrigger { /* private fields */ }
Expand description

Representation of a trigger.

Implementations§

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![],
        ))
    }
}

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![],
        ))
    }
}

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![],
        ))
    }
}

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![],
        ))
    }
}

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.