44 lines
1.4 KiB
Rust
44 lines
1.4 KiB
Rust
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
|
|
}
|
|
}
|