1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
use crate::QueryResult; use crate::value::display_value; use super::utils::escape_csv_field; pub fn render_csv(result: &QueryResult) -> String { let mut output = String::new(); output.push_str( &result .columns .iter() .map(|column| escape_csv_field(column)) .collect::<Vec<_>>() .join(","), ); for row in &result.rows { output.push('\n'); output.push_str( &row.iter() .map(display_value) .map(|value| escape_csv_field(&value)) .collect::<Vec<_>>() .join(","), ); } output }