Added query parameters.
This commit is contained in:
@@ -5,8 +5,14 @@ use crate::database::{
|
||||
dtos::recurring_transaction::RecurringTransactionRow,
|
||||
};
|
||||
|
||||
pub struct Query {
|
||||
pub limit: Option<i64>,
|
||||
pub offset: Option<i64>,
|
||||
}
|
||||
|
||||
pub async fn query_recurring_transactions<'e, E>(
|
||||
executor: E,
|
||||
query: Query,
|
||||
) -> Result<Vec<RecurringTransactionRow>, sqlx::Error>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
@@ -26,7 +32,10 @@ where
|
||||
weekend_adjustment
|
||||
FROM recurring_transactions
|
||||
ORDER BY starts_at DESC, id DESC
|
||||
LIMIT $1 OFFSET $2
|
||||
"#,
|
||||
query.limit,
|
||||
query.offset,
|
||||
)
|
||||
.fetch_all(executor)
|
||||
.await
|
||||
|
||||
@@ -5,7 +5,15 @@ use crate::database::{
|
||||
dtos::transaction::TransactionRow,
|
||||
};
|
||||
|
||||
pub async fn query_transactions<'e, E>(executor: E) -> Result<Vec<TransactionRow>, sqlx::Error>
|
||||
pub struct Query {
|
||||
pub limit: Option<i64>,
|
||||
pub offset: Option<i64>,
|
||||
}
|
||||
|
||||
pub async fn query_transactions<'e, E>(
|
||||
executor: E,
|
||||
query: Query,
|
||||
) -> Result<Vec<TransactionRow>, sqlx::Error>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -15,7 +23,11 @@ where
|
||||
SELECT id, description, amount_cents, direction, date
|
||||
FROM transactions
|
||||
ORDER BY date DESC, id DESC
|
||||
LIMIT $1
|
||||
OFFSET $2
|
||||
"#,
|
||||
query.limit,
|
||||
query.offset,
|
||||
)
|
||||
.fetch_all(executor)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user