Function
format_csv
(result: &QueryResult, no_header: bool, writer: &mut W)
Source from the content-addressed store, hash-verified
| 67 | } |
| 68 | |
| 69 | fn format_csv<W: Write>(result: &QueryResult, no_header: bool, writer: &mut W) -> Result<()> { |
| 70 | let mut csv_writer = csv::Writer::from_writer(writer); |
| 71 | |
| 72 | if !no_header { |
| 73 | csv_writer.write_record(&result.columns)?; |
| 74 | } |
| 75 | |
| 76 | for row in &result.rows { |
| 77 | let string_row: Vec<String> = row.iter().map(value_to_string).collect(); |
| 78 | csv_writer.write_record(&string_row)?; |
| 79 | } |
| 80 | |
| 81 | csv_writer.flush()?; |
| 82 | Ok(()) |
| 83 | } |
| 84 | |
| 85 | fn value_to_string(value: &Value) -> String { |
| 86 | match value { |
Tested by
no test coverage detected