1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Optimize request

This commit is contained in:
Pierre HUBERT 2020-05-24 18:02:19 +02:00
parent 75024dbca6
commit 816e349368
2 changed files with 10 additions and 1 deletions

View File

@ -70,7 +70,8 @@ pub fn get_user_by_login_token(token: &str, client: &APIClient) -> ResultBoxErro
database::query_row( database::query_row(
QueryInfo::new(USER_ACCESS_TOKENS_TABLE) QueryInfo::new(USER_ACCESS_TOKENS_TABLE)
.cond_u32("service_id", client.id) .cond_u32("service_id", client.id)
.cond("token1", token), .cond("token1", token)
.add_field("user_id"),
|res| res.get_int64("user_id"), |res| res.get_int64("user_id"),
) )
} }

View File

@ -60,6 +60,8 @@ pub struct QueryInfo {
pub limit: u64, pub limit: u64,
/// Queried arguments /// Queried arguments
///
/// If this attribute is empty, all the columns of the table set are fetched
pub fields: Vec<String>, pub fields: Vec<String>,
} }
@ -88,6 +90,12 @@ impl QueryInfo {
self.conditions.insert(key.to_string(), val.to_string()); self.conditions.insert(key.to_string(), val.to_string());
self 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 /// Struct used to read the result of a request