diff options
-rw-r--r-- | src/db/mod.rs | 2 | ||||
-rw-r--r-- | src/db/utils.rs | 12 | ||||
-rw-r--r-- | src/main.rs | 1 |
3 files changed, 13 insertions, 2 deletions
diff --git a/src/db/mod.rs b/src/db/mod.rs index a0aa3dc..f5facd1 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -3,4 +3,4 @@ pub mod incomes; pub mod jobs; pub mod payments; pub mod users; -mod utils; +pub mod utils; diff --git a/src/db/utils.rs b/src/db/utils.rs index 2ff0f13..26435e0 100644 --- a/src/db/utils.rs +++ b/src/db/utils.rs @@ -1,5 +1,15 @@ use crate::model::report::Report; -use tokio_rusqlite::Row; +use tokio_rusqlite::{Connection, Row}; + +pub async fn support_foreign_keys(conn: &Connection) { + let query = r#"PRAGMA foreign_keys = ON"#; + + let res = conn.call(move |conn| Ok(conn.execute(query, [])?)).await; + + if let Err(err) = res { + log::error!("Error supporting foreign keys: {err:?}"); + } +} pub fn format_key_for_search(value: &str) -> String { // Lower doesn’t work on accentuated letters, hence the need to remove manually accents for diff --git a/src/main.rs b/src/main.rs index 0786f46..18713bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { .unwrap_or_else(|_| { panic!("Error while openning DB: {}", config.db_path) }); + db::utils::support_foreign_keys(&db_conn).await; let assets = assets::get(); |