Skip to main content

query_forge/output/formats/
jsonl.rs

1use crate::{QueryResult, QueryValue};
2
3use super::utils::{escape_json_string, to_json_value};
4
5pub fn render_jsonl(result: &QueryResult) -> String {
6    let mut output = String::new();
7
8    for (row_index, row) in result.rows.iter().enumerate() {
9        if row_index > 0 {
10            output.push('\n');
11        }
12        output.push('{');
13        for (column_index, column) in result.columns.iter().enumerate() {
14            if column_index > 0 {
15                output.push(',');
16            }
17            output.push_str(&escape_json_string(column));
18            output.push(':');
19            output.push_str(&to_json_value(
20                row.get(column_index).unwrap_or(&QueryValue::Null),
21            ));
22        }
23        output.push('}');
24    }
25
26    output
27}