Parse query result from JSON output
(json_str: &str)
| 161 | impl CliQueryResult { |
| 162 | /// Parse query result from JSON output |
| 163 | fn from_json(json_str: &str) -> Result<Self, Box<dyn std::error::Error>> { |
| 164 | // Find where JSON starts (skip any log lines before it) |
| 165 | let json_start = json_str.find('{').ok_or("No JSON found in output")?; |
| 166 | |
| 167 | let json_portion = &json_str[json_start..]; |
| 168 | let parsed: JsonValue = serde_json::from_str(json_portion)?; |
| 169 | |
| 170 | // Extract rows from JSON |
| 171 | let empty_vec = vec![]; |
| 172 | let rows = parsed["rows"].as_array().unwrap_or(&empty_vec); |
| 173 | |
| 174 | let converted_rows: Vec<Row> = rows |
| 175 | .iter() |
| 176 | .map(|row| { |
| 177 | let mut values = HashMap::new(); |
| 178 | if let Some(obj) = row.as_object() { |
| 179 | for (key, val) in obj { |
| 180 | values.insert(key.clone(), json_value_to_storage_value(val)); |
| 181 | } |
| 182 | } |
| 183 | Row { values } |
| 184 | }) |
| 185 | .collect(); |
| 186 | |
| 187 | Ok(CliQueryResult { |
| 188 | rows: converted_rows, |
| 189 | }) |
| 190 | } |
| 191 | |
| 192 | /// Get the number of rows |
| 193 | pub fn len(&self) -> usize { |
nothing calls this directly
no test coverage detected