Skip to content

Commit

Permalink
Update fn get_tables_of_database
Browse files Browse the repository at this point in the history
  • Loading branch information
TaQuangKhoi committed Aug 19, 2024
1 parent 670f566 commit f29e1c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/core/get_knowledge.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rusqlite::{Connection, params};
use rusqlite::{Connection, MappedRows, params, Row};
use crate::core::table::{ExportComplexityType, Table, TableType};

const SQLITE_DATABASE_PATH: &str = "twodb.db";
Expand Down Expand Up @@ -37,13 +37,14 @@ pub fn get_tables() -> Vec<Table> {
let mut result = Vec::new();
for table in tables {
let mut inner_table = table.unwrap();
inner_table.update_row_count();
inner_table.update_row_count(); // Long running query
result.push(inner_table);
}
result
}

pub fn get_tables_of_database(database_name: &String) -> MappedRows<fn(&Row) -> rusqlite::Result<Table>> {
pub fn get_tables_of_database(database_name: &String) -> Vec<Table>
{
let sqlite_conn = Connection::open(SQLITE_DATABASE_PATH).unwrap();
let mut stmt = sqlite_conn.prepare(
"SELECT
Expand Down Expand Up @@ -76,5 +77,9 @@ pub fn get_tables_of_database(database_name: &String) -> MappedRows<fn(&Row) ->
is_exported: false,
})
}).unwrap();
tables_iter
let mut result = Vec::new();
for table in tables_iter {
result.push(table.unwrap());
}
result
}
10 changes: 4 additions & 6 deletions src/menu_bar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ impl TwoDBApp {
let source_database_name = var("POSTGRES_DB_SOURCE").unwrap_or(String::from(""));

let tables_from_sqlite = get_tables_of_database(&source_database_name);
// for row in source_rows {
// let columns: &[Column] = row.columns();
// let table_name = columns[0].name();
// move_one_table(table_name);
// }
for table in tables_from_sqlite {
println!("Found table {:?}", table.name);
}

let text = format!("Done Get Tables for {}", source_database_name);
let text = format!("Done Move Tables for {}", source_database_name);
TwoDBApp::notify(text, is_busy, toast_text);
});
}
Expand Down

0 comments on commit f29e1c4

Please sign in to comment.