From 816e349368fc4e80aaf80e72f20974c8cd30f5c4 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 24 May 2020 18:02:19 +0200 Subject: [PATCH] Optimize request --- src/helpers/account_helper.rs | 3 ++- src/helpers/database.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index 968ca2e..582e352 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -70,7 +70,8 @@ pub fn get_user_by_login_token(token: &str, client: &APIClient) -> ResultBoxErro database::query_row( QueryInfo::new(USER_ACCESS_TOKENS_TABLE) .cond_u32("service_id", client.id) - .cond("token1", token), + .cond("token1", token) + .add_field("user_id"), |res| res.get_int64("user_id"), ) } \ No newline at end of file diff --git a/src/helpers/database.rs b/src/helpers/database.rs index 7f53d74..4174174 100644 --- a/src/helpers/database.rs +++ b/src/helpers/database.rs @@ -60,6 +60,8 @@ pub struct QueryInfo { pub limit: u64, /// Queried arguments + /// + /// If this attribute is empty, all the columns of the table set are fetched pub fields: Vec, } @@ -88,6 +90,12 @@ impl QueryInfo { self.conditions.insert(key.to_string(), val.to_string()); self } + + /// Append a field to the list of selected fields + pub fn add_field(mut self, key: &str) -> QueryInfo { + self.fields.push(key.to_string()); + self + } } /// Struct used to read the result of a request