Added name query to accounts and updated query handling.
This commit is contained in:
+3
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n\t\tSELECT id, name\n\t\tFROM accounts\n\t\tORDER BY name DESC, id DESC\n\t\tLIMIT $1\n\t\tOFFSET $2\n\t\t",
|
||||
"query": "\n\t\tSELECT id, name\n\t\tFROM accounts\n\t\tWHERE ($1::text IS NULL OR name ILIKE '%' || $1 || '%')\n\t\tORDER BY name DESC, id DESC\n\t\tLIMIT $2\n\t\tOFFSET $3\n\t\t",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
@@ -16,6 +16,7 @@
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text",
|
||||
"Int8",
|
||||
"Int8"
|
||||
]
|
||||
@@ -25,5 +26,5 @@
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "b7bfaaed62475d82b8d551e1c9223ae42f06e1534d9587b876dbc494c9eeaebc"
|
||||
"hash": "9b5267c3bd09fb64717565c5c7e3084195d09c0a30f7e963a2497892398c6adc"
|
||||
}
|
||||
@@ -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>,
|
||||
|
||||
@@ -10,15 +10,27 @@ use crate::{
|
||||
};
|
||||
|
||||
pub struct Query {
|
||||
pub name: Option<String>,
|
||||
pub limit: Option<u64>,
|
||||
pub offset: Option<u64>,
|
||||
}
|
||||
|
||||
impl Default for Query {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: None,
|
||||
limit: None,
|
||||
offset: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Query> for db::Query {
|
||||
type Error = QueryConversionError;
|
||||
|
||||
fn try_from(query: Query) -> Result<Self, Self::Error> {
|
||||
Ok(db::Query {
|
||||
name: query.name,
|
||||
limit: query
|
||||
.limit
|
||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||
@@ -27,6 +39,7 @@ impl TryFrom<Query> for db::Query {
|
||||
.offset
|
||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||
.transpose()?,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,15 @@ pub struct Query {
|
||||
pub offset: Option<u64>,
|
||||
}
|
||||
|
||||
impl Default for Query {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
limit: None,
|
||||
offset: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Query> for db::Query {
|
||||
type Error = QueryConversionError;
|
||||
|
||||
@@ -31,6 +40,7 @@ impl TryFrom<Query> for db::Query {
|
||||
.offset
|
||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||
.transpose()?,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,15 @@ pub struct Query {
|
||||
pub offset: Option<u64>,
|
||||
}
|
||||
|
||||
impl Default for Query {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
limit: None,
|
||||
offset: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Query> for db::Query {
|
||||
type Error = QueryConversionError;
|
||||
|
||||
@@ -28,6 +37,7 @@ impl TryFrom<Query> for db::Query {
|
||||
.offset
|
||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||
.transpose()?,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ pub fn create_router() -> axum::Router<PgPool> {
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct QueryParams {
|
||||
pub name: Option<String>,
|
||||
pub limit: Option<u64>,
|
||||
pub offset: Option<u64>,
|
||||
}
|
||||
@@ -37,8 +38,10 @@ impl TryFrom<QueryParams> for repository::Query {
|
||||
|
||||
fn try_from(query: QueryParams) -> Result<Self, Self::Error> {
|
||||
Ok(repository::Query {
|
||||
name: query.name,
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ impl TryFrom<QueryParams> for repository::Query {
|
||||
Ok(repository::Query {
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ impl TryFrom<QueryParams> for repository::Query {
|
||||
Ok(repository::Query {
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user