1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#[derive(Clone, Debug, PartialEq, Eq, elephantry_derive::Entity)]
#[elephantry(internal)]
pub struct Trigger {
    pub action: String,
    pub event: String,
    pub name: String,
    pub orientation: String,
    pub table: String,
    pub timing: String,
}

pub fn triggers(connection: &crate::Connection, schema: &str) -> crate::Result<Vec<Trigger>> {
    connection
        .query(
            r#"
select t.trigger_name as name,
    t.event_manipulation as event,
    t.action_statement as action,
    t.action_timing as timing,
    event_object_table as table,
    t.action_orientation orientation
from information_schema.triggers t
where t.trigger_schema = $*
order by t.trigger_name;
"#,
            &[&schema],
        )
        .map(Iterator::collect)
}