Skip to content

Commit ef26006

Browse files
committed
Fix tables list: honor --table filter and fall through on --limit/--cursor
When an active database is set, --table now passes through to the API instead of being silently dropped. --limit and --cursor fall through to tables::list (which supports pagination) rather than the active-db path.
1 parent 43dde92 commit ef26006

2 files changed

Lines changed: 25 additions & 7 deletions

File tree

‎src/commands/databases.rs‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -766,14 +766,19 @@ fn download_to_temp(
766766
Ok(temp)
767767
}
768768

769-
fn collect_tables(api: &Api, connection_id: &str, schema: Option<&str>) -> Vec<InfoTable> {
769+
fn collect_tables(
770+
api: &Api,
771+
connection_id: &str,
772+
schema: Option<&str>,
773+
table: Option<&str>,
774+
) -> Vec<InfoTable> {
770775
let mut out = Vec::new();
771776
let mut cursor: Option<String> = None;
772777
loop {
773778
let resp = crate::client::sdk::block(api.client().information_schema().get(
774779
Some(connection_id),
775780
schema,
776-
None,
781+
table,
777782
None,
778783
None,
779784
cursor.as_deref(),
@@ -1333,7 +1338,13 @@ pub fn delete(workspace_id: &str, id_or_name: &str) {
13331338
println!("{}", "Database deleted.".green());
13341339
}
13351340

1336-
pub fn tables_list(workspace_id: &str, database: Option<&str>, schema: Option<&str>, format: &str) {
1341+
pub fn tables_list(
1342+
workspace_id: &str,
1343+
database: Option<&str>,
1344+
schema: Option<&str>,
1345+
table: Option<&str>,
1346+
format: &str,
1347+
) {
13371348
let database = resolve_current_database(database, workspace_id);
13381349
let api = Api::new(Some(workspace_id));
13391350
let db = resolve_database(&api, &database);
@@ -1342,7 +1353,7 @@ pub fn tables_list(workspace_id: &str, database: Option<&str>, schema: Option<&s
13421353
.as_deref()
13431354
.or(db.name.as_deref())
13441355
.unwrap_or("default");
1345-
let tables = collect_tables(&api, &db.default_connection_id, schema);
1356+
let tables = collect_tables(&api, &db.default_connection_id, schema, table);
13461357

13471358
let rows = table_rows(catalog, tables);
13481359

@@ -1473,7 +1484,7 @@ pub fn tables_load(
14731484
// The table wasn't declared at create time. Collect existing tables so
14741485
// they are re-declared in the replacement database, then delete and
14751486
// recreate with all tables (including the new one) declared.
1476-
let existing = collect_tables(&api, &db.default_connection_id, None);
1487+
let existing = collect_tables(&api, &db.default_connection_id, None, None);
14771488
let mut all_tables: Vec<String> = existing
14781489
.iter()
14791490
.map(|t| format!("{}.{}", t.schema, t.table))
@@ -2098,7 +2109,7 @@ mod tests {
20982109
.create();
20992110

21002111
let api = Api::test_new(&server.url(), "k", Some("ws"));
2101-
let tables = collect_tables(&api, "conn1", None);
2112+
let tables = collect_tables(&api, "conn1", None, None);
21022113
page0.assert();
21032114
page1.assert();
21042115
assert_eq!(tables.len(), 2);

‎src/main.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ fn main() {
327327
&workspace_id,
328328
db_flag.as_deref().or(database.as_deref()),
329329
schema.as_deref(),
330+
None,
330331
&output,
331332
),
332333
Some(DatabaseTablesCommands::Load {
@@ -363,6 +364,7 @@ fn main() {
363364
&workspace_id,
364365
Some(db.as_str()),
365366
None,
367+
None,
366368
"table",
367369
)
368370
} else {
@@ -408,11 +410,16 @@ fn main() {
408410
output,
409411
} => {
410412
let workspace_id = resolve_workspace(workspace_id);
411-
if crate::config::load_current_database("default", &workspace_id).is_some() {
413+
let use_db_path = limit.is_none()
414+
&& cursor.is_none()
415+
&& crate::config::load_current_database("default", &workspace_id)
416+
.is_some();
417+
if use_db_path {
412418
databases::tables_list(
413419
&workspace_id,
414420
None,
415421
schema.as_deref(),
422+
table.as_deref(),
416423
&output,
417424
)
418425
} else {

0 commit comments

Comments
 (0)