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

Method query_raw

nodedb-client/src/remote/client/core.rs:64–95  ·  view source on GitHub ↗

Execute a raw SQL string and return rows as `Vec >`.

(
        &self,
        sql: &str,
        params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
    )

Source from the content-addressed store, hash-verified

62
63 /// Execute a raw SQL string and return rows as `Vec<Vec<Value>>`.
64 pub(super) async fn query_raw(
65 &self,
66 sql: &str,
67 params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
68 ) -> NodeDbResult<(Vec<String>, Vec<Vec<Value>>)> {
69 let client = self.client.lock().await;
70 let rows = client.query(sql, params).await.map_err(|e| {
71 NodeDbError::storage(format!("pgwire query failed: {}", pg_error_detail(&e)))
72 })?;
73
74 if rows.is_empty() {
75 return Ok((Vec::new(), Vec::new()));
76 }
77
78 let columns: Vec<String> = rows[0]
79 .columns()
80 .iter()
81 .map(|c| c.name().to_string())
82 .collect();
83
84 let mut result_rows = Vec::with_capacity(rows.len());
85 for row in &rows {
86 let mut vals = Vec::with_capacity(columns.len());
87 for (i, col) in row.columns().iter().enumerate() {
88 let val = pg_value_to_value(row, i, col.type_());
89 vals.push(val);
90 }
91 result_rows.push(vals);
92 }
93
94 Ok((columns, result_rows))
95 }
96
97 /// Execute a statement that doesn't return rows (INSERT/UPDATE/DELETE).
98 pub(super) async fn execute_raw(

Callers 5

document_get_implMethod · 0.80
execute_sql_implMethod · 0.80
vector_search_implMethod · 0.80

Calls 11

pg_value_to_valueFunction · 0.85
lockMethod · 0.80
collectMethod · 0.80
to_stringMethod · 0.80
queryMethod · 0.45
is_emptyMethod · 0.45
iterMethod · 0.45
columnsMethod · 0.45
nameMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected