use tokio_postgres::{Client, SimpleQueryMessage, SimpleQueryRow};
use crate::PostgresError;
pub async fn simple_query_opt(
client: &Client,
query: &str,
) -> Result<Option<SimpleQueryRow>, PostgresError> {
let result = client.simple_query(query).await?;
let mut rows = result.into_iter().filter_map(|msg| match msg {
SimpleQueryMessage::Row(row) => Some(row),
_ => None,
});
match (rows.next(), rows.next()) {
(Some(row), None) => Ok(Some(row)),
(None, None) => Ok(None),
_ => Err(PostgresError::UnexpectedRow),
}
}