Added name query to accounts and updated query handling.

This commit is contained in:
2026-09-27 10:32:08 +02:00
parent bb58e3fd77
commit d219d63dca
10 changed files with 74 additions and 4 deletions
+15 -2
View File
@@ -3,10 +3,21 @@ use uuid::Uuid;
use super::dtos::{AccountRow, Delete, Upsert};
pub struct Query {
pub name: Option<String>,
pub limit: Option<i64>,
pub offset: Option<i64>,
}
impl Default for Query {
fn default() -> Self {
Self {
name: None,
limit: None,
offset: None,
}
}
}
pub async fn query<'e, E>(executor: E, query: Query) -> Result<Vec<AccountRow>, sqlx::Error>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
@@ -16,10 +27,12 @@ where
r#"
SELECT id, name
FROM accounts
WHERE ($1::text IS NULL OR name ILIKE '%' || $1 || '%')
ORDER BY name DESC, id DESC
LIMIT $1
OFFSET $2
LIMIT $2
OFFSET $3
"#,
query.name,
query.limit,
query.offset,
)
@@ -7,6 +7,15 @@ pub struct Query {
pub offset: Option<i64>,
}
impl Default for Query {
fn default() -> Self {
Self {
limit: None,
offset: None,
}
}
}
pub async fn query<'e, E>(
executor: E,
query: Query,
+9
View File
@@ -7,6 +7,15 @@ pub struct Query {
pub offset: Option<i64>,
}
impl Default for Query {
fn default() -> Self {
Self {
limit: None,
offset: None,
}
}
}
pub async fn query<'e, E>(executor: E, query: Query) -> Result<Vec<TransactionRow>, sqlx::Error>
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,