use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use sqlx::{any::AnyRow, FromRow, Row as _};
pub mod manager;
#[async_trait]
pub trait TxManager {
async fn find_all_auth_commits_for_stele(
&mut self,
stele_id: &str,
) -> anyhow::Result<Vec<DataRepoCommits>>;
async fn insert_bulk(&mut self, data_repo_commits: Vec<DataRepoCommits>) -> anyhow::Result<()>;
}
#[derive(Debug, Deserialize, Serialize)]
pub struct DataRepoCommits {
pub commit_hash: String,
pub codified_date: Option<String>,
pub build_date: Option<String>,
pub repo_type: String,
pub auth_commit_hash: String,
pub auth_commit_timestamp: String,
pub publication_id: String,
}
impl DataRepoCommits {
#[must_use]
pub const fn new(
commit_hash: String,
codified_date: Option<String>,
build_date: Option<String>,
repo_type: String,
auth_commit_hash: String,
auth_commit_timestamp: String,
publication_id: String,
) -> Self {
Self {
commit_hash,
codified_date,
build_date,
repo_type,
auth_commit_hash,
auth_commit_timestamp,
publication_id,
}
}
}
impl FromRow<'_, AnyRow> for DataRepoCommits {
fn from_row(row: &AnyRow) -> anyhow::Result<Self, sqlx::Error> {
Ok(Self {
commit_hash: row.try_get("commit_hash")?,
codified_date: row.try_get("codified_date").ok(),
build_date: row.try_get("build_date").ok(),
repo_type: row.try_get("repo_type")?,
auth_commit_hash: row.try_get("auth_commit_hash")?,
auth_commit_timestamp: row.try_get("auth_commit_timestamp")?,
publication_id: row.try_get("publication_id")?,
})
}
}