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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//this avoids dependency on sqlx-sqlite-cipher in rxqlite-client amo.
#![deny(warnings)]
#![allow(non_camel_case_types)]
use serde::{Serialize, Deserialize};

//https://github.com/rusqlite/rusqlite/blob/b41bd805710149ebfaed577dfedb464338e2ca97/src/hooks.rs#L17

pub mod ffi_3_14_0 {
  //https://github.com/rusqlite/rusqlite/blob/master/libsqlite3-sys/bindgen-bindings/bindgen_3.14.0.rs
  pub const SQLITE_DELETE: i32 = 9;
  pub const SQLITE_INSERT: i32 = 18;
  pub const SQLITE_UPDATE: i32 = 23;
}
use ffi_3_14_0 as ffi;

/// Action Codes
#[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
#[non_exhaustive]
#[allow(clippy::upper_case_acronyms)]
pub enum Action {
    /// Unsupported / unexpected action
    UNKNOWN = -1,
    /// DELETE command
    SQLITE_DELETE = ffi::SQLITE_DELETE,
    /// INSERT command
    SQLITE_INSERT = ffi::SQLITE_INSERT,
    /// UPDATE command
    SQLITE_UPDATE = ffi::SQLITE_UPDATE,
}

impl From<i32> for Action {
    #[inline]
    fn from(code: i32) -> Action {
        match code {
            ffi::SQLITE_DELETE => Action::SQLITE_DELETE,
            ffi::SQLITE_INSERT => Action::SQLITE_INSERT,
            ffi::SQLITE_UPDATE => Action::SQLITE_UPDATE,
            _ => Action::UNKNOWN,
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Notification {
    Update {
        action: Action,
        database: String,
        table: String,
        row_id: i64,
    },
}