24 lines
551 B
Rust
24 lines
551 B
Rust
// src/adresar/handlers/get_adresar_count.rs
|
|
use tonic::Status;
|
|
use sqlx::PgPool;
|
|
use crate::proto::multieko2::common::{CountResponse, Empty};
|
|
|
|
pub async fn get_adresar_count(
|
|
db_pool: &PgPool,
|
|
_request: Empty,
|
|
) -> Result<CountResponse, Status> {
|
|
let count: i64 = sqlx::query_scalar!(
|
|
r#"
|
|
SELECT COUNT(*) AS count
|
|
FROM adresar
|
|
WHERE deleted = FALSE
|
|
"#
|
|
)
|
|
.fetch_one(db_pool)
|
|
.await
|
|
.map_err(|e| Status::internal(e.to_string()))?
|
|
.unwrap_or(0);
|
|
|
|
Ok(CountResponse { count })
|
|
}
|