This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-12-09 15:18:32 +03:00
parent c6d3246f71
commit a93ed4e9aa
14 changed files with 228 additions and 19 deletions

View file

@ -268,6 +268,23 @@ pub async fn read_all_id_for_surname(
.collect::<Vec<i64>>())
}
pub async fn read_all_id_for_birth_date(
birth_date: &NaiveDate,
database_connection: &Pool<Postgres>,
) -> Result<Vec<i64>, sqlx::Error> {
Ok(sqlx::query!(
r#"
SELECT "id" FROM "user" WHERE "birth_date" = $1
"#,
birth_date
)
.fetch_all(database_connection)
.await?
.iter()
.map(|record| record.id)
.collect::<Vec<i64>>())
}
pub async fn count_all(database_connection: &Pool<Postgres>) -> Result<u64, sqlx::Error> {
sqlx::query!(
r#"
@ -353,3 +370,21 @@ pub async fn count_all_for_surname(
.try_into()
.or(Ok(0))
}
pub async fn count_all_for_birth_date(
birth_date: &NaiveDate,
database_connection: &Pool<Postgres>,
) -> Result<u64, sqlx::Error> {
sqlx::query!(
r#"
SELECT COUNT(id) FROM "user" WHERE "birth_date" = $1
"#,
birth_date
)
.fetch_one(database_connection)
.await?
.count
.map_or(0, |count| count)
.try_into()
.or(Ok(0))
}