Format results as CSV
(result: &QueryResult)
| 120 | |
| 121 | /// Format results as CSV |
| 122 | fn format_csv(result: &QueryResult) -> String { |
| 123 | let mut output = String::new(); |
| 124 | |
| 125 | // CSV header |
| 126 | output.push_str(&result.variables.join(",")); |
| 127 | output.push('\n'); |
| 128 | |
| 129 | // CSV rows |
| 130 | for row in &result.rows { |
| 131 | let row_values: Vec<String> = result |
| 132 | .variables |
| 133 | .iter() |
| 134 | .map(|col| { |
| 135 | row.get_value(col) |
| 136 | .map(Self::value_to_csv_string) |
| 137 | .unwrap_or_else(|| "".to_string()) |
| 138 | }) |
| 139 | .collect(); |
| 140 | output.push_str(&row_values.join(",")); |
| 141 | output.push('\n'); |
| 142 | } |
| 143 | |
| 144 | // Add warnings as CSV comments |
| 145 | if !result.warnings.is_empty() { |
| 146 | output.push_str("\n# Warnings:\n"); |
| 147 | for (i, warning) in result.warnings.iter().enumerate() { |
| 148 | output.push_str(&format!("# {}. {}\n", i + 1, warning)); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | output |
| 153 | } |
| 154 | |
| 155 | /// Convert a Value to a display string |
| 156 | fn value_to_string(value: &Value) -> String { |