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

Simplify future database requests

This commit is contained in:
Pierre HUBERT 2020-05-24 16:39:48 +02:00
parent f0cf3202f4
commit 3b1b377d82
2 changed files with 12 additions and 2 deletions

View File

@ -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<UserAccessToken> {
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")?,

View File

@ -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