MCPcopy Create free account
hub / github.com/douglance/devsql / format_table

Function format_table

crates/vcsql/src/cli/output.rs:22–52  ·  view source on GitHub ↗
(result: &QueryResult, no_header: bool, writer: &mut W)

Source from the content-addressed store, hash-verified

20}
21
22fn format_table<W: Write>(result: &QueryResult, no_header: bool, writer: &mut W) -> Result<()> {
23 if result.is_empty() {
24 return Ok(());
25 }
26
27 let rows: Vec<Vec<String>> = result
28 .rows
29 .iter()
30 .map(|row| row.iter().map(value_to_string).collect())
31 .collect();
32
33 let mut builder = tabled::builder::Builder::default();
34
35 if !no_header {
36 builder.push_record(&result.columns);
37 }
38
39 for row in &rows {
40 builder.push_record(row);
41 }
42
43 let mut table = builder.build();
44 table.with(Style::rounded());
45
46 // Limit column width for readability
47 table.with(Width::truncate(80).suffix("..."));
48
49 writeln!(writer, "{}", table)?;
50
51 Ok(())
52}
53
54fn format_json<W: Write>(result: &QueryResult, writer: &mut W) -> Result<()> {
55 let json_array = result.to_json_array();

Callers 1

format_outputFunction · 0.85

Calls 1

is_emptyMethod · 0.80

Tested by

no test coverage detected