working get count properly for adresar
This commit is contained in:
19
src/adresar/handlers/get_adresar_count.rs
Normal file
19
src/adresar/handlers/get_adresar_count.rs
Normal 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 })
|
||||
}
|
||||
Reference in New Issue
Block a user