From 6fde3901a41f2ee7452b8c8afed4bc4bb116aad8 Mon Sep 17 00:00:00 2001 From: Flix Date: Sat, 5 Feb 2022 15:29:53 +0100 Subject: [PATCH] feat: function to check if a job id exists --- src/spawn.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/spawn.rs b/src/spawn.rs index 2035cad..d08e374 100644 --- a/src/spawn.rs +++ b/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 { + let exists = sqlx::query_scalar("SELECT EXISTS(SELECT id FROM mq_msgs WHERE id = $1)") + .bind(id) + .fetch_one(executor) + .await?; + Ok(exists) +}