Skip to main content

apalis_sqlite/queries/
fetch_by_id.rs

1use apalis_core::{
2    backend::{Backend, FetchById},
3    task::{Task, task_id::TaskId},
4};
5
6use crate::{SqliteStorage, SqliteTask, error::Error, from_row::SqliteTaskRow};
7
8impl<Args> FetchById for SqliteStorage<Args>
9where
10    Self: Backend<Error = Error, Task = Task<Vec<u8>>>,
11    Args: 'static,
12{
13    fn fetch_by_id(
14        &mut self,
15        id: &TaskId,
16    ) -> impl Future<Output = Result<Option<SqliteTask>, Self::Error>> + Send {
17        let pool = self.persistence.pool.clone();
18        let id = id.to_string();
19        async move {
20            let task = sqlx::query_file_as!(SqliteTaskRow, "queries/task/find_by_id.sql", id)
21                .fetch_optional(&pool)
22                .await?
23                .map(|r| r.try_into())
24                .transpose()?;
25            Ok(task)
26        }
27    }
28}