Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 129 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ open = "5"
rand = "0.8"
sha2 = "0.10"
tiny_http = "0.12"
comfy-table = "7"
tabled = { version = "0.20", features = ["ansi"] }
inquire = "0.9.4"
indicatif = "0.17"
nix = { version = "0.29", features = ["fs"] }
Expand Down
26 changes: 16 additions & 10 deletions src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ pub fn types_list(workspace_id: &str, format: &str) {
"json" => println!("{}", serde_json::to_string_pretty(&body.connection_types).unwrap()),
"yaml" => print!("{}", serde_yaml::to_string(&body.connection_types).unwrap()),
"table" => {
let mut table = crate::util::make_table();
table.set_header(["NAME", "LABEL"]);
for ct in &body.connection_types {
table.add_row([&ct.name, &ct.label]);
if body.connection_types.is_empty() {
use crossterm::style::Stylize;
eprintln!("{}", "No connection types found.".dark_grey());
} else {
let rows: Vec<Vec<String>> = body.connection_types.iter()
.map(|ct| vec![ct.name.clone(), ct.label.clone()])
.collect();
crate::table::print(&["NAME", "LABEL"], &rows);
}
println!("{table}");
}
_ => unreachable!(),
}
Expand Down Expand Up @@ -312,12 +315,15 @@ pub fn list(workspace_id: &str, format: &str) {
print!("{}", serde_yaml::to_string(&body.connections).unwrap());
}
"table" => {
let mut table = crate::util::make_table();
table.set_header(["ID", "NAME", "SOURCE TYPE"]);
for c in &body.connections {
table.add_row([&c.id, &c.name, &c.source_type]);
if body.connections.is_empty() {
use crossterm::style::Stylize;
eprintln!("{}", "No connections found.".dark_grey());
} else {
let rows: Vec<Vec<String>> = body.connections.iter()
.map(|c| vec![c.id.clone(), c.name.clone(), c.source_type.clone()])
.collect();
crate::table::print(&["ID", "NAME", "SOURCE TYPE"], &rows);
}
println!("{table}");
}
_ => unreachable!(),
}
Expand Down
35 changes: 17 additions & 18 deletions src/datasets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,17 +475,18 @@ pub fn list(workspace_id: &str, limit: Option<u32>, offset: Option<u32>, format:
"json" => println!("{}", serde_json::to_string_pretty(&body.datasets).unwrap()),
"yaml" => print!("{}", serde_yaml::to_string(&body.datasets).unwrap()),
"table" => {
let mut table = crate::util::make_table();
table.set_header(["ID", "LABEL", "FULL NAME", "CREATED AT"]);
table.column_mut(1).unwrap().set_constraint(
comfy_table::ColumnConstraint::UpperBoundary(comfy_table::Width::Fixed(30))
);
for d in &body.datasets {
let created_at = d.created_at.split('.').next().unwrap_or(&d.created_at).replace('T', " ");
let full_name = format!("datasets.main.{}", d.table_name);
table.add_row([&d.id, &d.label, &full_name, &created_at]);
if body.datasets.is_empty() {
use crossterm::style::Stylize;
eprintln!("{}", "No datasets found.".dark_grey());
} else {
let rows: Vec<Vec<String>> = body.datasets.iter().map(|d| vec![
d.id.clone(),
d.label.clone(),
format!("datasets.main.{}", d.table_name),
crate::util::format_date(&d.created_at),
]).collect();
crate::table::print(&["ID", "LABEL", "FULL NAME", "CREATED AT"], &rows);
}
println!("{table}");
if body.has_more {
let next = offset.unwrap_or(0) + body.count as u32;
use crossterm::style::Stylize;
Expand Down Expand Up @@ -547,8 +548,8 @@ pub fn get(dataset_id: &str, workspace_id: &str, format: &str) {
"json" => println!("{}", serde_json::to_string_pretty(&d).unwrap()),
"yaml" => print!("{}", serde_yaml::to_string(&d).unwrap()),
"table" => {
let created_at = d.created_at.split('.').next().unwrap_or(&d.created_at).replace('T', " ");
let updated_at = d.updated_at.split('.').next().unwrap_or(&d.updated_at).replace('T', " ");
let created_at = crate::util::format_date(&d.created_at);
let updated_at = crate::util::format_date(&d.updated_at);
println!("id: {}", d.id);
println!("label: {}", d.label);
println!("full_name: datasets.main.{}", d.table_name);
Expand All @@ -557,12 +558,10 @@ pub fn get(dataset_id: &str, workspace_id: &str, format: &str) {
println!("updated_at: {updated_at}");
if !d.columns.is_empty() {
println!();
let mut table = crate::util::make_table();
table.set_header(["COLUMN", "DATA TYPE", "NULLABLE"]);
for col in &d.columns {
table.add_row([&col.name, &col.data_type, &col.nullable.to_string()]);
}
println!("{table}");
let rows: Vec<Vec<String>> = d.columns.iter().map(|col| vec![
col.name.clone(), col.data_type.clone(), col.nullable.to_string(),
]).collect();
crate::table::print(&["COLUMN", "DATA TYPE", "NULLABLE"], &rows);
}
}
_ => unreachable!(),
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod init;
mod query;
mod results;
mod skill;
mod table;
mod tables;
mod util;
mod workspace;
Expand Down
8 changes: 1 addition & 7 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,7 @@ pub fn execute(sql: &str, workspace_id: &str, connection: Option<&str>, format:
}
}
"table" => {
let mut table = crate::util::make_table();
table.set_header(&result.columns);
for row in &result.rows {
let cells: Vec<String> = row.iter().map(value_to_string).collect();
table.add_row(cells);
}
println!("{table}");
crate::table::print_json(&result.columns, &result.rows);
use crossterm::style::Stylize;
let id_part = result.result_id.as_deref().map(|id| format!(" [result-id: {id}]")).unwrap_or_default();
eprintln!("{}", format!("\n{} row{} ({} ms){}", result.row_count, if result.row_count == 1 { "" } else { "s" }, result.execution_time_ms, id_part).dark_grey());
Expand Down
8 changes: 1 addition & 7 deletions src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,7 @@ pub fn get(result_id: &str, workspace_id: &str, format: &str) {
}
}
"table" => {
let mut table = crate::util::make_table();
table.set_header(&result.columns);
for row in &result.rows {
let cells: Vec<String> = row.iter().map(value_to_string).collect();
table.add_row(cells);
}
println!("{table}");
crate::table::print_json(&result.columns, &result.rows);
use crossterm::style::Stylize;
eprintln!("{}", format!("\n{} row{} ({} ms) [result-id: {}]", result.row_count, if result.row_count == 1 { "" } else { "s" }, result.execution_time_ms, result.result_id).dark_grey());
}
Expand Down
Loading
Loading