Execute a SQL statement, returning every row as a Vec of its column values (in projection order). Column count is taken from the first row received.
(&self, sql: &str)
| 88 | /// values (in projection order). Column count is taken from the first |
| 89 | /// row received. |
| 90 | pub async fn query_rows(&self, sql: &str) -> Result<Vec<Vec<String>>, String> { |
| 91 | let client = self.client.as_ref(); |
| 92 | match client.simple_query(sql).await { |
| 93 | Ok(msgs) => { |
| 94 | let mut rows: Vec<Vec<String>> = Vec::new(); |
| 95 | for msg in msgs { |
| 96 | if let tokio_postgres::SimpleQueryMessage::Row(row) = msg { |
| 97 | let n = row.len(); |
| 98 | let mut cols: Vec<String> = Vec::with_capacity(n); |
| 99 | for i in 0..n { |
| 100 | cols.push(row.get(i).unwrap_or("").to_string()); |
| 101 | } |
| 102 | rows.push(cols); |
| 103 | } |
| 104 | } |
| 105 | Ok(rows) |
| 106 | } |
| 107 | Err(e) => Err(pg_error_detail(&e)), |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /// Execute a SQL statement expecting success (no result needed). |
| 112 | pub async fn exec(&self, sql: &str) -> Result<(), String> { |