mz_postgres_util/
query.rs1use tokio_postgres::{Client, SimpleQueryMessage, SimpleQueryRow};
11
12use crate::PostgresError;
13
14pub async fn simple_query_opt(
16 client: &Client,
17 query: &str,
18) -> Result<Option<SimpleQueryRow>, PostgresError> {
19 let result = client.simple_query(query).await?;
20 let mut rows = result.into_iter().filter_map(|msg| match msg {
21 SimpleQueryMessage::Row(row) => Some(row),
22 _ => None,
23 });
24 match (rows.next(), rows.next()) {
25 (Some(row), None) => Ok(Some(row)),
26 (None, None) => Ok(None),
27 _ => Err(PostgresError::UnexpectedRow),
28 }
29}