mirror of
https://github.com/Diggsey/sqlxmq.git
synced 2024-11-25 01:31:03 +00:00
Merge pull request #21 from FlixCoder/job-exists
feat: function to check if a job id exists
This commit is contained in:
commit
7a13e04b21
1 changed files with 12 additions and 0 deletions
12
src/spawn.rs
12
src/spawn.rs
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue