Layer query simplification.

This commit is contained in:
2026-10-08 21:32:44 +02:00
parent c51e9425d6
commit 3709fcbe02
12 changed files with 82 additions and 232 deletions
+13 -29
View File
@@ -17,21 +17,13 @@ pub struct Query {
pub offset: Option<u64>,
}
impl Default for Query {
fn default() -> Self {
Self {
name: None,
limit: None,
offset: None,
}
}
}
impl TryFrom<Query> for db::Query {
type Error = QueryConversionError;
fn try_from(query: Query) -> Result<Self, Self::Error> {
Ok(db::Query {
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Account>, RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let accounts = db::list(
executor,
db::Query {
name: query.name,
limit: query
.limit
@@ -41,20 +33,12 @@ impl TryFrom<Query> for db::Query {
.offset
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
.transpose()?,
..Default::default()
})
}
}
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Account>, RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let accounts = db::list(executor, query.try_into()?)
.await?
.into_iter()
.map(decode)
.collect::<Result<_, DecodeError>>()?;
},
)
.await?
.into_iter()
.map(decode)
.collect::<Result<_, DecodeError>>()?;
Ok(accounts)
}