Execute a parameterless statement via the simple-query protocol (single `Query` message — no `Parse`/`Bind`/`Describe` round-trip). Required for DDL statements that don't fit the extended-query row-description shape that `Client::query` expects. `simple_query` doesn't support bound parameters, so callers with non-empty params must continue to use `query_raw`. All values come back as strings from
(
&self,
sql: &str,
)
| 118 | /// we wrap them as `Value::String` and let downstream consumers |
| 119 | /// coerce as needed. |
| 120 | pub(super) async fn simple_query_raw( |
| 121 | &self, |
| 122 | sql: &str, |
| 123 | ) -> NodeDbResult<(Vec<String>, Vec<Vec<Value>>)> { |
| 124 | use tokio_postgres::SimpleQueryMessage; |
| 125 | |
| 126 | let client = self.client.lock().await; |
| 127 | let messages = client.simple_query(sql).await.map_err(|e| { |
| 128 | NodeDbError::storage(format!( |
| 129 | "pgwire simple_query failed: {}", |
| 130 | pg_error_detail(&e) |
| 131 | )) |
| 132 | })?; |
| 133 | |
| 134 | let mut columns: Vec<String> = Vec::new(); |
| 135 | let mut rows: Vec<Vec<Value>> = Vec::new(); |
| 136 | |
| 137 | for msg in messages { |
| 138 | match msg { |
| 139 | SimpleQueryMessage::RowDescription(fields) => { |
| 140 | columns = fields.iter().map(|f| f.name().to_string()).collect(); |
| 141 | } |
| 142 | SimpleQueryMessage::Row(row) => { |
| 143 | let mut vals = Vec::with_capacity(row.len()); |
| 144 | for i in 0..row.len() { |
| 145 | match row.get(i) { |
| 146 | Some(s) => vals.push(Value::String(s.to_string())), |
| 147 | None => vals.push(Value::Null), |
| 148 | } |
| 149 | } |
| 150 | rows.push(vals); |
| 151 | } |
| 152 | SimpleQueryMessage::CommandComplete(_) => { |
| 153 | // DDL / DML completion — no rows. |
| 154 | } |
| 155 | _ => {} |
| 156 | } |
| 157 | } |
| 158 | Ok((columns, rows)) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | #[cfg(test)] |
no test coverage detected