working get count properly for adresar

This commit is contained in:
filipriec
2025-02-18 14:40:23 +01:00
parent 93968b2b2f
commit 9ff6dada40
7 changed files with 113 additions and 2 deletions

View File

@@ -0,0 +1,19 @@
// src/adresar/handlers/get_adresar_count.rs
use tonic::{Status};
use sqlx::PgPool;
use crate::proto::multieko2::{CountResponse, Empty};
pub async fn get_adresar_count(
db_pool: &PgPool,
_request: Empty,
) -> Result<CountResponse, Status> {
let count: i64 = sqlx::query_scalar!(
"SELECT COUNT(*) as count FROM adresar"
)
.fetch_one(db_pool)
.await
.map_err(|e| Status::internal(e.to_string()))?
.unwrap_or(0); // Handle the case where the count is None
Ok(CountResponse { count })
}