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 -28
View File
@@ -15,20 +15,13 @@ pub struct Query {
pub offset: Option<u64>,
}
impl Default for Query {
fn default() -> Self {
Self {
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<Transaction>, RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let transactions = db::list(
executor,
db::Query {
limit: query
.limit
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
@@ -37,20 +30,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<Transaction>, RepositoryError>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let transactions = db::list(executor, query.try_into()?)
.await?
.into_iter()
.map(decode)
.collect::<Result<_, DecodeError>>()?;
},
)
.await?
.into_iter()
.map(decode)
.collect::<Result<_, DecodeError>>()?;
Ok(transactions)
}