|
| 1 | +use crate::schema::trustpub_configs_github; |
| 2 | +use chrono::{DateTime, Utc}; |
| 3 | +use diesel::prelude::*; |
| 4 | +use diesel_async::{AsyncPgConnection, RunQueryDsl}; |
| 5 | + |
| 6 | +#[derive(Debug, Identifiable, Queryable, Selectable)] |
| 7 | +#[diesel(table_name = trustpub_configs_github, check_for_backend(diesel::pg::Pg))] |
| 8 | +pub struct GitHubConfig { |
| 9 | + pub id: i32, |
| 10 | + pub crate_id: i32, |
| 11 | + pub repository_owner: String, |
| 12 | + pub repository_owner_id: i32, |
| 13 | + pub repository_name: String, |
| 14 | + pub workflow_filename: String, |
| 15 | + pub environment: Option<String>, |
| 16 | + pub created_at: DateTime<Utc>, |
| 17 | +} |
| 18 | + |
| 19 | +#[derive(Debug, Insertable)] |
| 20 | +#[diesel(table_name = trustpub_configs_github, check_for_backend(diesel::pg::Pg))] |
| 21 | +pub struct NewGitHubConfig<'a> { |
| 22 | + pub crate_id: i32, |
| 23 | + pub repository_owner: &'a str, |
| 24 | + pub repository_owner_id: i32, |
| 25 | + pub repository_name: &'a str, |
| 26 | + pub workflow_filename: &'a str, |
| 27 | + pub environment: Option<&'a str>, |
| 28 | +} |
| 29 | + |
| 30 | +impl NewGitHubConfig<'_> { |
| 31 | + pub async fn insert(&self, conn: &mut AsyncPgConnection) -> QueryResult<GitHubConfig> { |
| 32 | + self.insert_into(trustpub_configs_github::table) |
| 33 | + .returning(GitHubConfig::as_returning()) |
| 34 | + .get_result(conn) |
| 35 | + .await |
| 36 | + } |
| 37 | +} |
0 commit comments