From 2956aa5f5324e4183dbc87f81fbc71fd0f43dbf9 Mon Sep 17 00:00:00 2001 From: Joris Date: Thu, 6 Feb 2025 19:10:54 +0100 Subject: Improve String handling See https://blog.sulami.xyz/posts/string-vs-str/ --- src/db/incomes.rs | 6 +++--- src/db/utils.rs | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/db') diff --git a/src/db/incomes.rs b/src/db/incomes.rs index 90282c0..688e9e1 100644 --- a/src/db/incomes.rs +++ b/src/db/incomes.rs @@ -373,8 +373,8 @@ fn cumulative_query(from: NaiveDate) -> String { ON users.id = incomes.user_id "#, - bounded_query(">".to_string(), from.format("%Y-%m-%d").to_string()), - bounded_query("<".to_string(), "date()".to_string()) + bounded_query(">", &from.format("%Y-%m-%d").to_string()), + bounded_query("<", "date()") ) } @@ -382,7 +382,7 @@ fn cumulative_query(from: NaiveDate) -> String { /// /// It filters incomes according to the operator and date, /// and adds the income at this date. -fn bounded_query(op: String, date: String) -> String { +fn bounded_query(op: &str, date: &str) -> String { format!( r#" SELECT diff --git a/src/db/utils.rs b/src/db/utils.rs index 30f25c9..bd4d867 100644 --- a/src/db/utils.rs +++ b/src/db/utils.rs @@ -2,7 +2,9 @@ use crate::model::report::Report; use tokio_rusqlite::{Connection, Row}; pub async fn support_foreign_keys(conn: &Connection) { - let res = conn.call(move |conn| Ok(conn.pragma_update(None, "foreign_keys", "ON"))).await; + let res = conn + .call(move |conn| Ok(conn.pragma_update(None, "foreign_keys", "ON"))) + .await; if let Err(err) = res { log::error!("Error supporting foreign keys: {err:?}"); -- cgit v1.2.3