Run a SQL query and return the first column of every result row.
(client: &tokio_postgres::Client, sql: &str)
| 29 | |
| 30 | /// Run a SQL query and return the first column of every result row. |
| 31 | async fn query_col0(client: &tokio_postgres::Client, sql: &str) -> Vec<String> { |
| 32 | let msgs = client.simple_query(sql).await.unwrap_or_else(|e| { |
| 33 | let detail = if let Some(db) = e.as_db_error() { |
| 34 | format!( |
| 35 | "SQLSTATE={} severity={} msg={}", |
| 36 | db.code().code(), |
| 37 | db.severity(), |
| 38 | db.message() |
| 39 | ) |
| 40 | } else { |
| 41 | format!("{e:?}") |
| 42 | }; |
| 43 | panic!("query failed: {detail}\n sql: {sql}") |
| 44 | }); |
| 45 | msgs.into_iter() |
| 46 | .filter_map(|m| { |
| 47 | if let tokio_postgres::SimpleQueryMessage::Row(r) = m { |
| 48 | r.get(0).map(|s| s.to_string()) |
| 49 | } else { |
| 50 | None |
| 51 | } |
| 52 | }) |
| 53 | .collect() |
| 54 | } |
| 55 | |
| 56 | /// Parse the `attrs[0]` int64 from a single ARRAY_SLICE result row. |
| 57 | /// |
no test coverage detected