Added name query to accounts and updated query handling.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user