apps: get all with filter, serde

This commit is contained in:
Philippe Loctaux 2023-03-30 00:53:57 +02:00
parent 842be36a1b
commit 42d88cc2dd
9 changed files with 259 additions and 1 deletions

View file

@ -16,6 +16,35 @@ pub struct Apps {
}
impl Apps {
pub async fn get_all(
conn: impl SqliteExecutor<'_>,
filter_get_archived: Option<bool>,
) -> Result<Vec<Self>, Error> {
match filter_get_archived {
Some(true) => {
// Get all archived apps
sqlx::query_file_as!(Self, "queries/apps/get_all_archived.sql")
.fetch_all(conn)
.await
.map_err(handle_error)
}
Some(false) => {
// Get all active apps
sqlx::query_file_as!(Self, "queries/apps/get_all_active.sql")
.fetch_all(conn)
.await
.map_err(handle_error)
}
None => {
// Get all apps
sqlx::query_file_as!(Self, "queries/apps/get_all.sql")
.fetch_all(conn)
.await
.map_err(handle_error)
}
}
}
pub async fn insert(
conn: impl SqliteExecutor<'_>,
id: &str,