Layer query simplification.
This commit is contained in:
@@ -14,20 +14,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<User>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let users = db::list(
|
||||
executor,
|
||||
db::Query {
|
||||
limit: query
|
||||
.limit
|
||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||
@@ -36,20 +29,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<User>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let users = db::list(executor, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<_, DecodeError>>()?;
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<_, DecodeError>>()?;
|
||||
|
||||
Ok(users)
|
||||
}
|
||||
@@ -84,9 +69,7 @@ where
|
||||
}
|
||||
|
||||
fn classify_delete_error(error: DatabaseError) -> RepositoryError {
|
||||
match &error {
|
||||
_ => RepositoryError::Database(error),
|
||||
}
|
||||
RepositoryError::Database(error)
|
||||
}
|
||||
|
||||
fn decode(row: UserRow) -> Result<User, DecodeError> {
|
||||
|
||||
Reference in New Issue
Block a user