MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / query_col0

Function query_col0

nodedb-cluster-tests/tests/bitemporal_array_cluster.rs:31–54  ·  view source on GitHub ↗

Run a SQL query and return the first column of every result row.

(client: &tokio_postgres::Client, sql: &str)

Source from the content-addressed store, hash-verified

29
30/// Run a SQL query and return the first column of every result row.
31async 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///

Calls 3

collectMethod · 0.80
to_stringMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected