Skip to content

Commit f8b74ac

Browse files
committed
database: Add NewUsedJti data access object
1 parent e636437 commit f8b74ac

File tree

2 files changed

+26
-0
lines changed

2 files changed

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

34
pub use self::github_config::{GitHubConfig, NewGitHubConfig};
5+
pub use self::used_jti::NewUsedJti;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::schema::trustpub_used_jtis;
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_used_jtis, check_for_backend(diesel::pg::Pg))]
8+
pub struct NewUsedJti<'a> {
9+
pub jti: &'a str,
10+
pub expires_at: DateTime<Utc>,
11+
}
12+
13+
impl<'a> NewUsedJti<'a> {
14+
pub fn new(jti: &'a str, expires_at: DateTime<Utc>) -> Self {
15+
Self { jti, expires_at }
16+
}
17+
18+
pub async fn insert(&self, conn: &mut AsyncPgConnection) -> QueryResult<usize> {
19+
diesel::insert_into(trustpub_used_jtis::table)
20+
.values(self)
21+
.execute(conn)
22+
.await
23+
}
24+
}

0 commit comments

Comments
 (0)