From 3b1b377d82de4fcb02ef573113a781a43c2ddd4b Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 24 May 2020 16:39:48 +0200 Subject: [PATCH] Simplify future database requests --- src/helpers/account_helper.rs | 4 ++-- src/helpers/database.rs | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index 09409ef..8fa6578 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -53,8 +53,8 @@ pub fn login_user(email: &str, password: &str, client: &APIClient) -> ResultBoxE fn get_client_tokens(user_id: UserID, client: &APIClient) -> ResultBoxError { database::query_row( QueryInfo::new(USER_ACCESS_TOKENS_TABLE) - .cond("user_id", user_id.to_string().as_ref()) - .cond("service_id", client.id.to_string().as_ref()), + .cond_i64("user_id", user_id) + .cond_u32("service_id", client.id), |res| { Ok(UserAccessToken { user_id: res.get_int64("user_id")?, diff --git a/src/helpers/database.rs b/src/helpers/database.rs index 84518aa..7f53d74 100644 --- a/src/helpers/database.rs +++ b/src/helpers/database.rs @@ -78,6 +78,16 @@ impl QueryInfo { self.conditions.insert(key.to_string(), val.to_string()); self } + + pub fn cond_u32(mut self, key: &str, val: u32) -> QueryInfo { + self.conditions.insert(key.to_string(), val.to_string()); + self + } + + pub fn cond_i64(mut self, key: &str, val: i64) -> QueryInfo { + self.conditions.insert(key.to_string(), val.to_string()); + self + } } /// Struct used to read the result of a request