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
+43
View File
@@ -0,0 +1,43 @@
use sqlx::PgPool;
use uuid::Uuid;
use super::issue::Issue;
impl Issue {
pub async fn find_by_id(pool: &PgPool, id: Uuid) -> Result<Option<Self>, sqlx::Error> {
sqlx::query_as::<_, Issue>(
"SELECT id, workspace_id, author_id, number, title, body, state, priority, visibility, \
locked, milestone_id, closed_by, closed_at, due_at, created_at, updated_at, deleted_at \
FROM issue WHERE id = $1 AND deleted_at IS NULL",
)
.bind(id)
.fetch_optional(pool)
.await
}
pub async fn find_by_number(
pool: &PgPool,
workspace_id: Uuid,
number: i64,
) -> Result<Option<Self>, sqlx::Error> {
sqlx::query_as::<_, Issue>(
"SELECT id, workspace_id, author_id, number, title, body, state, priority, visibility, \
locked, milestone_id, closed_by, closed_at, due_at, created_at, updated_at, deleted_at \
FROM issue WHERE workspace_id = $1 AND number = $2 AND deleted_at IS NULL",
)
.bind(workspace_id)
.bind(number)
.fetch_optional(pool)
.await
}
pub async fn next_number<'e, E>(executor: E, workspace_id: Uuid) -> Result<i64, sqlx::Error>
where
E: sqlx::PgExecutor<'e>,
{
sqlx::query_scalar("SELECT COALESCE(MAX(number), 0) + 1 FROM issue WHERE workspace_id = $1")
.bind(workspace_id)
.fetch_one(executor)
.await
}
}