feat: init

This commit is contained in:
zhenyi
2026-06-07 11:30:56 +08:00
commit 563381c1ca
361 changed files with 41327 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
use sqlx::PgPool;
use uuid::Uuid;
use super::pull_request::PullRequest;
impl PullRequest {
pub async fn find_by_id(pool: &PgPool, id: Uuid) -> Result<Option<Self>, sqlx::Error> {
sqlx::query_as::<_, PullRequest>(
"SELECT id, repo_id, author_id, number, title, body, state, source_repo_id, \
source_branch, target_repo_id, target_branch, base_commit_sha, head_commit_sha, \
merge_commit_sha, draft, locked, merged_by, merged_at, closed_by, closed_at, \
created_at, updated_at, deleted_at \
FROM pull_request WHERE id = $1 AND deleted_at IS NULL",
)
.bind(id)
.fetch_optional(pool)
.await
}
pub async fn find_by_number(
pool: &PgPool,
repo_id: Uuid,
number: i64,
) -> Result<Option<Self>, sqlx::Error> {
sqlx::query_as::<_, PullRequest>(
"SELECT id, repo_id, author_id, number, title, body, state, source_repo_id, \
source_branch, target_repo_id, target_branch, base_commit_sha, head_commit_sha, \
merge_commit_sha, draft, locked, merged_by, merged_at, closed_by, closed_at, \
created_at, updated_at, deleted_at \
FROM pull_request WHERE repo_id = $1 AND number = $2 AND deleted_at IS NULL",
)
.bind(repo_id)
.bind(number)
.fetch_optional(pool)
.await
}
pub async fn next_number<'e, E>(executor: E, repo_id: Uuid) -> Result<i64, sqlx::Error>
where
E: sqlx::PgExecutor<'e>,
{
sqlx::query_scalar(
"SELECT COALESCE(MAX(number), 0) + 1 FROM pull_request WHERE repo_id = $1",
)
.bind(repo_id)
.fetch_one(executor)
.await
}
}