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

Method query_named_rows

nodedb-test-support/src/pgwire_harness/query.rs:60–85  ·  view source on GitHub ↗

Execute a SQL statement, returning every row as a `HashMap` keyed by the column name reported in the row description. Useful for tests that need to assert on specific projected columns regardless of projection order. NULL columns are stored as the empty string.

(
        &self,
        sql: &str,
    )

Source from the content-addressed store, hash-verified

58 /// that need to assert on specific projected columns regardless of
59 /// projection order. NULL columns are stored as the empty string.
60 pub async fn query_named_rows(
61 &self,
62 sql: &str,
63 ) -> Result<Vec<std::collections::HashMap<String, String>>, String> {
64 let client = self.client.as_ref();
65 match client.simple_query(sql).await {
66 Ok(msgs) => {
67 let mut rows: Vec<std::collections::HashMap<String, String>> = Vec::new();
68 for msg in msgs {
69 if let tokio_postgres::SimpleQueryMessage::Row(row) = msg {
70 // `SimpleColumn` is not `Clone`; collect names by
71 // borrowing the column slice directly.
72 let names: Vec<String> =
73 row.columns().iter().map(|c| c.name().to_string()).collect();
74 let mut map = std::collections::HashMap::with_capacity(names.len());
75 for (i, name) in names.into_iter().enumerate() {
76 map.insert(name, row.get(i).unwrap_or("").to_string());
77 }
78 rows.push(map);
79 }
80 }
81 Ok(rows)
82 }
83 Err(e) => Err(pg_error_detail(&e)),
84 }
85 }
86
87 /// Execute a SQL statement, returning every row as a Vec of its column
88 /// values (in projection order). Column count is taken from the first

Calls 11

collectMethod · 0.80
to_stringMethod · 0.80
pg_error_detailFunction · 0.70
as_refMethod · 0.45
iterMethod · 0.45
columnsMethod · 0.45
nameMethod · 0.45
lenMethod · 0.45
insertMethod · 0.45
getMethod · 0.45
pushMethod · 0.45