-
Notifications
You must be signed in to change notification settings - Fork 11
/
api_tokens.rs
48 lines (43 loc) · 1.28 KB
/
api_tokens.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use crate::db::{schema::api_tokens, DB};
use crate::v0::api_token::APIToken;
use diesel::{ExpressionMethods, Insertable, Queryable};
#[derive(Debug, Clone)]
pub struct APITokenData {
pub token: APIToken,
pub creation_time: i64,
pub expire_time: i64,
}
impl Queryable<api_tokens::SqlType, DB> for APITokenData {
type Row = (
// 0 -> token
Vec<u8>,
// 1 -> creation_time
i64,
// 2-> expire_time
i64,
);
fn build(row: Self::Row) -> Self {
Self {
token: APIToken::new(row.0),
creation_time: row.1,
expire_time: row.2,
}
}
}
// This warning is disabled here. Values is only referenced as a type here. It should be ok not to
// split the types definitions.
#[allow(clippy::type_complexity)]
impl Insertable<api_tokens::table> for APITokenData {
type Values = (
diesel::dsl::Eq<api_tokens::token, Vec<u8>>,
diesel::dsl::Eq<api_tokens::creation_time, i64>,
diesel::dsl::Eq<api_tokens::expire_time, i64>,
);
fn values(self) -> Self::Values {
(
api_tokens::token.eq(self.token.as_ref().to_vec()),
api_tokens::creation_time.eq(self.creation_time),
api_tokens::expire_time.eq(self.expire_time),
)
}
}