Skip to content

Commit c7ec53f

Browse files
committed
database: Add GitLabConfig model structs
1 parent f15e904 commit c7ec53f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::schema::trustpub_configs_gitlab;
2+
use chrono::{DateTime, Utc};
3+
use diesel::prelude::*;
4+
use diesel_async::{AsyncPgConnection, RunQueryDsl};
5+
use serde::Serialize;
6+
7+
#[derive(Debug, Identifiable, Queryable, Selectable, Serialize)]
8+
#[diesel(table_name = trustpub_configs_gitlab, check_for_backend(diesel::pg::Pg))]
9+
pub struct GitLabConfig {
10+
pub id: i32,
11+
pub created_at: DateTime<Utc>,
12+
pub crate_id: i32,
13+
pub namespace: String,
14+
pub project: String,
15+
pub workflow_filepath: String,
16+
pub environment: Option<String>,
17+
}
18+
19+
#[derive(Debug, Insertable)]
20+
#[diesel(table_name = trustpub_configs_gitlab, check_for_backend(diesel::pg::Pg))]
21+
pub struct NewGitLabConfig<'a> {
22+
pub crate_id: i32,
23+
pub namespace: &'a str,
24+
pub project: &'a str,
25+
pub workflow_filepath: &'a str,
26+
pub environment: Option<&'a str>,
27+
}
28+
29+
impl NewGitLabConfig<'_> {
30+
pub async fn insert(&self, conn: &mut AsyncPgConnection) -> QueryResult<GitLabConfig> {
31+
self.insert_into(trustpub_configs_gitlab::table)
32+
.returning(GitLabConfig::as_returning())
33+
.get_result(conn)
34+
.await
35+
}
36+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
mod data;
22
mod github_config;
3+
mod gitlab_config;
34
mod token;
45
mod used_jti;
56

67
pub use self::data::TrustpubData;
78
pub use self::github_config::{GitHubConfig, NewGitHubConfig};
9+
pub use self::gitlab_config::{GitLabConfig, NewGitLabConfig};
810
pub use self::token::NewToken;
911
pub use self::used_jti::NewUsedJti;

0 commit comments

Comments
 (0)