Skip to content

Commit 46f612a

Browse files
committed
Trusted Publishing: Add NewToken data access object
1 parent 46ceb2b commit 46f612a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
mod github_config;
2+
mod token;
23

34
pub use self::github_config::{GitHubConfig, NewGitHubConfig};
5+
pub use self::token::NewToken;
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)