Condensed classifiers in one place
This commit is contained in:
parent
cf7fc2ec87
commit
e336292db4
8 changed files with 256 additions and 34 deletions
|
|
@ -101,6 +101,32 @@ impl Transaction {
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
pub async fn list_by_user(
|
||||
pool: &SqlitePool,
|
||||
user: i32,
|
||||
limit: i32,
|
||||
offset: i32,
|
||||
asc: bool,
|
||||
) -> Result<Vec<Self>> {
|
||||
let rows = sqlx::query(
|
||||
if asc {
|
||||
"SELECT t.* FROM transactions t JOIN accounts a ON a.account_id=t.account WHERE a.user=? ORDER BY transaction_timestamp ASC LIMIT ? OFFSET ?"
|
||||
} else {
|
||||
"SELECT t.* FROM transactions t JOIN accounts a ON a.account_id=t.account WHERE a.user=? ORDER BY transaction_timestamp DESC LIMIT ? OFFSET ?"
|
||||
}
|
||||
).bind(user)
|
||||
.bind(limit)
|
||||
.bind(offset)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
|
||||
let mut res = Vec::new();
|
||||
for r in &rows {
|
||||
res.push(Transaction::from_row(r)?);
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn query_by_date<'a>(
|
||||
account: i32,
|
||||
after: Option<DateTime<Utc>>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue