Merge pull request #21 from FlixCoder/job-exists

feat: function to check if a job id exists
This commit is contained in:
Diggory Blake 2022-02-05 14:46:21 +00:00 committed by GitHub
commit 7a13e04b21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -171,3 +171,15 @@ pub async fn clear_all<'b, E: sqlx::Executor<'b, Database = Postgres>>(
.await?;
Ok(())
}
/// Check if a job with that ID exists
pub async fn exists<'b, E: sqlx::Executor<'b, Database = Postgres>>(
executor: E,
id: Uuid,
) -> Result<bool, sqlx::Error> {
let exists = sqlx::query_scalar("SELECT EXISTS(SELECT id FROM mq_msgs WHERE id = $1)")
.bind(id)
.fetch_one(executor)
.await?;
Ok(exists)
}