Layer query simplification.
This commit is contained in:
@@ -11,16 +11,6 @@ pub struct Query {
|
|||||||
pub offset: Option<i64>,
|
pub offset: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
name: None,
|
|
||||||
limit: None,
|
|
||||||
offset: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<AccountRow>, DatabaseError>
|
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<AccountRow>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
|
|||||||
@@ -10,15 +10,6 @@ pub struct Query {
|
|||||||
pub offset: Option<i64>,
|
pub offset: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
limit: None,
|
|
||||||
offset: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn list<'e, E>(
|
pub async fn list<'e, E>(
|
||||||
executor: E,
|
executor: E,
|
||||||
query: Query,
|
query: Query,
|
||||||
|
|||||||
@@ -10,15 +10,6 @@ pub struct Query {
|
|||||||
pub offset: Option<i64>,
|
pub offset: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
limit: None,
|
|
||||||
offset: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<TransactionRow>, DatabaseError>
|
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<TransactionRow>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
|
|||||||
@@ -11,16 +11,6 @@ pub struct Query {
|
|||||||
pub offset: Option<i64>,
|
pub offset: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
app_id: Uuid::nil(),
|
|
||||||
limit: None,
|
|
||||||
offset: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppSecretRow>, DatabaseError>
|
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppSecretRow>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
|
|||||||
@@ -11,16 +11,6 @@ pub struct Query {
|
|||||||
pub offset: Option<i64>,
|
pub offset: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
user_id: Uuid::nil(),
|
|
||||||
limit: None,
|
|
||||||
offset: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppRow>, DatabaseError>
|
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppRow>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
|
|||||||
@@ -10,15 +10,6 @@ pub struct Query {
|
|||||||
pub offset: Option<i64>,
|
pub offset: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
limit: None,
|
|
||||||
offset: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserRow>, DatabaseError>
|
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserRow>, DatabaseError>
|
||||||
where
|
where
|
||||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
|
|||||||
@@ -17,21 +17,13 @@ pub struct Query {
|
|||||||
pub offset: Option<u64>,
|
pub offset: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Account>, RepositoryError>
|
||||||
fn default() -> Self {
|
where
|
||||||
Self {
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
name: None,
|
{
|
||||||
limit: None,
|
let accounts = db::list(
|
||||||
offset: None,
|
executor,
|
||||||
}
|
db::Query {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<Query> for db::Query {
|
|
||||||
type Error = QueryConversionError;
|
|
||||||
|
|
||||||
fn try_from(query: Query) -> Result<Self, Self::Error> {
|
|
||||||
Ok(db::Query {
|
|
||||||
name: query.name,
|
name: query.name,
|
||||||
limit: query
|
limit: query
|
||||||
.limit
|
.limit
|
||||||
@@ -41,20 +33,12 @@ impl TryFrom<Query> for db::Query {
|
|||||||
.offset
|
.offset
|
||||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||||
.transpose()?,
|
.transpose()?,
|
||||||
..Default::default()
|
},
|
||||||
})
|
)
|
||||||
}
|
.await?
|
||||||
}
|
.into_iter()
|
||||||
|
.map(decode)
|
||||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Account>, RepositoryError>
|
.collect::<Result<_, DecodeError>>()?;
|
||||||
where
|
|
||||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
|
||||||
{
|
|
||||||
let accounts = db::list(executor, query.try_into()?)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(decode)
|
|
||||||
.collect::<Result<_, DecodeError>>()?;
|
|
||||||
|
|
||||||
Ok(accounts)
|
Ok(accounts)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,20 +20,16 @@ pub struct Query {
|
|||||||
pub offset: Option<u64>,
|
pub offset: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
pub async fn list<'e, E>(
|
||||||
fn default() -> Self {
|
executor: E,
|
||||||
Self {
|
query: Query,
|
||||||
limit: None,
|
) -> Result<Vec<RecurringTransaction>, RepositoryError>
|
||||||
offset: None,
|
where
|
||||||
}
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
}
|
{
|
||||||
}
|
let transactions = db::list(
|
||||||
|
executor,
|
||||||
impl TryFrom<Query> for db::Query {
|
db::Query {
|
||||||
type Error = QueryConversionError;
|
|
||||||
|
|
||||||
fn try_from(query: Query) -> Result<Self, Self::Error> {
|
|
||||||
Ok(db::Query {
|
|
||||||
limit: query
|
limit: query
|
||||||
.limit
|
.limit
|
||||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||||
@@ -42,23 +38,12 @@ impl TryFrom<Query> for db::Query {
|
|||||||
.offset
|
.offset
|
||||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||||
.transpose()?,
|
.transpose()?,
|
||||||
..Default::default()
|
},
|
||||||
})
|
)
|
||||||
}
|
.await?
|
||||||
}
|
.into_iter()
|
||||||
|
.map(decode)
|
||||||
pub async fn list<'e, E>(
|
.collect::<Result<_, DecodeError>>()?;
|
||||||
executor: E,
|
|
||||||
query: Query,
|
|
||||||
) -> Result<Vec<RecurringTransaction>, 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>>()?;
|
|
||||||
|
|
||||||
Ok(transactions)
|
Ok(transactions)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,20 +15,13 @@ pub struct Query {
|
|||||||
pub offset: Option<u64>,
|
pub offset: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Transaction>, RepositoryError>
|
||||||
fn default() -> Self {
|
where
|
||||||
Self {
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
limit: None,
|
{
|
||||||
offset: None,
|
let transactions = db::list(
|
||||||
}
|
executor,
|
||||||
}
|
db::Query {
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<Query> for db::Query {
|
|
||||||
type Error = QueryConversionError;
|
|
||||||
|
|
||||||
fn try_from(query: Query) -> Result<Self, Self::Error> {
|
|
||||||
Ok(db::Query {
|
|
||||||
limit: query
|
limit: query
|
||||||
.limit
|
.limit
|
||||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||||
@@ -37,20 +30,12 @@ impl TryFrom<Query> for db::Query {
|
|||||||
.offset
|
.offset
|
||||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||||
.transpose()?,
|
.transpose()?,
|
||||||
..Default::default()
|
},
|
||||||
})
|
)
|
||||||
}
|
.await?
|
||||||
}
|
.into_iter()
|
||||||
|
.map(decode)
|
||||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Transaction>, RepositoryError>
|
.collect::<Result<_, DecodeError>>()?;
|
||||||
where
|
|
||||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
|
||||||
{
|
|
||||||
let transactions = db::list(executor, query.try_into()?)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(decode)
|
|
||||||
.collect::<Result<_, DecodeError>>()?;
|
|
||||||
|
|
||||||
Ok(transactions)
|
Ok(transactions)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,21 +14,13 @@ pub struct Query {
|
|||||||
pub offset: Option<u64>,
|
pub offset: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppSecret>, RepositoryError>
|
||||||
fn default() -> Self {
|
where
|
||||||
Self {
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
app_id: Uuid::nil(),
|
{
|
||||||
limit: None,
|
Ok(db::list(
|
||||||
offset: None,
|
executor,
|
||||||
}
|
db::Query {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<Query> for db::Query {
|
|
||||||
type Error = QueryConversionError;
|
|
||||||
|
|
||||||
fn try_from(query: Query) -> Result<Self, Self::Error> {
|
|
||||||
Ok(db::Query {
|
|
||||||
app_id: query.app_id,
|
app_id: query.app_id,
|
||||||
limit: query
|
limit: query
|
||||||
.limit
|
.limit
|
||||||
@@ -40,19 +32,12 @@ impl TryFrom<Query> for db::Query {
|
|||||||
i64::try_from(offset).map_err(|_| QueryConversionError::Offset(offset))
|
i64::try_from(offset).map_err(|_| QueryConversionError::Offset(offset))
|
||||||
})
|
})
|
||||||
.transpose()?,
|
.transpose()?,
|
||||||
})
|
},
|
||||||
}
|
)
|
||||||
}
|
.await?
|
||||||
|
.into_iter()
|
||||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppSecret>, RepositoryError>
|
.map(decode)
|
||||||
where
|
.collect())
|
||||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
|
||||||
{
|
|
||||||
Ok(db::list(executor, query.try_into()?)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(decode)
|
|
||||||
.collect())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_by_id<'e, E>(
|
pub async fn get_by_id<'e, E>(
|
||||||
|
|||||||
@@ -12,21 +12,13 @@ pub struct Query {
|
|||||||
pub offset: Option<u64>,
|
pub offset: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserApp>, RepositoryError>
|
||||||
fn default() -> Self {
|
where
|
||||||
Self {
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
user_id: Uuid::nil(),
|
{
|
||||||
limit: None,
|
Ok(db::list(
|
||||||
offset: None,
|
executor,
|
||||||
}
|
db::Query {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<Query> for db::Query {
|
|
||||||
type Error = QueryConversionError;
|
|
||||||
|
|
||||||
fn try_from(query: Query) -> Result<Self, Self::Error> {
|
|
||||||
Ok(db::Query {
|
|
||||||
user_id: query.user_id,
|
user_id: query.user_id,
|
||||||
limit: query
|
limit: query
|
||||||
.limit
|
.limit
|
||||||
@@ -38,19 +30,12 @@ impl TryFrom<Query> for db::Query {
|
|||||||
i64::try_from(offset).map_err(|_| QueryConversionError::Offset(offset))
|
i64::try_from(offset).map_err(|_| QueryConversionError::Offset(offset))
|
||||||
})
|
})
|
||||||
.transpose()?,
|
.transpose()?,
|
||||||
})
|
},
|
||||||
}
|
)
|
||||||
}
|
.await?
|
||||||
|
.into_iter()
|
||||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserApp>, RepositoryError>
|
.map(decode)
|
||||||
where
|
.collect())
|
||||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
|
||||||
{
|
|
||||||
Ok(db::list(executor, query.try_into()?)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(decode)
|
|
||||||
.collect())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_by_id<'e, E>(
|
pub async fn get_by_id<'e, E>(
|
||||||
|
|||||||
@@ -14,20 +14,13 @@ pub struct Query {
|
|||||||
pub offset: Option<u64>,
|
pub offset: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Query {
|
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<User>, RepositoryError>
|
||||||
fn default() -> Self {
|
where
|
||||||
Self {
|
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||||
limit: None,
|
{
|
||||||
offset: None,
|
let users = db::list(
|
||||||
}
|
executor,
|
||||||
}
|
db::Query {
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<Query> for db::Query {
|
|
||||||
type Error = QueryConversionError;
|
|
||||||
|
|
||||||
fn try_from(query: Query) -> Result<Self, Self::Error> {
|
|
||||||
Ok(db::Query {
|
|
||||||
limit: query
|
limit: query
|
||||||
.limit
|
.limit
|
||||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||||
@@ -36,20 +29,12 @@ impl TryFrom<Query> for db::Query {
|
|||||||
.offset
|
.offset
|
||||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||||
.transpose()?,
|
.transpose()?,
|
||||||
..Default::default()
|
},
|
||||||
})
|
)
|
||||||
}
|
.await?
|
||||||
}
|
.into_iter()
|
||||||
|
.map(decode)
|
||||||
pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<User>, RepositoryError>
|
.collect::<Result<_, DecodeError>>()?;
|
||||||
where
|
|
||||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
|
||||||
{
|
|
||||||
let users = db::list(executor, query.try_into()?)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(decode)
|
|
||||||
.collect::<Result<_, DecodeError>>()?;
|
|
||||||
|
|
||||||
Ok(users)
|
Ok(users)
|
||||||
}
|
}
|
||||||
@@ -84,9 +69,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn classify_delete_error(error: DatabaseError) -> RepositoryError {
|
fn classify_delete_error(error: DatabaseError) -> RepositoryError {
|
||||||
match &error {
|
RepositoryError::Database(error)
|
||||||
_ => RepositoryError::Database(error),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode(row: UserRow) -> Result<User, DecodeError> {
|
fn decode(row: UserRow) -> Result<User, DecodeError> {
|
||||||
|
|||||||
Reference in New Issue
Block a user