Skip to content

Commit 1d78c55

Browse files
committed
database: Add NewToken data access object
1 parent 1bd578a commit 1d78c55

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
mod github_config;
2+
mod token;
23
mod used_jti;
34

45
pub use self::github_config::{GitHubConfig, NewGitHubConfig};
6+
pub use self::token::NewToken;
57
pub use self::used_jti::NewUsedJti;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::schema::trustpub_tokens;
2+
use chrono::{DateTime, Utc};
3+
use diesel::prelude::*;
4+
use diesel_async::{AsyncPgConnection, RunQueryDsl};
5+
6+
#[derive(Debug, Insertable)]
7+
#[diesel(table_name = trustpub_tokens, check_for_backend(diesel::pg::Pg))]
8+
pub struct NewToken<'a> {
9+
pub expires_at: DateTime<Utc>,
10+
pub hashed_token: &'a [u8],
11+
pub crate_ids: &'a [i32],
12+
}
13+
14+
impl NewToken<'_> {
15+
pub async fn insert(&self, conn: &mut AsyncPgConnection) -> QueryResult<()> {
16+
self.insert_into(trustpub_tokens::table)
17+
.execute(conn)
18+
.await?;
19+
20+
Ok(())
21+
}
22+
}

0 commit comments

Comments
 (0)