Skip to content

Commit

Permalink
Update fn update_all_tables
Browse files Browse the repository at this point in the history
  • Loading branch information
TaQuangKhoi committed Aug 15, 2024
1 parent eb431de commit 15e562a
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/working_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,35 @@ pub fn get_cells(row: &postgres::Row) -> Vec<String> {

pub fn update_all_tables(database_name: &String) {
let mut client = connect(database_name.clone()).unwrap();
let query =
"SELECT table_name, table_type
let query = "
SELECT table_name, table_type
FROM information_schema.tables
WHERE table_schema = 'public'"
.to_string();
WHERE table_schema = 'public'
AND table_type = 'BASE TABLE'
".to_string();

let rows = client.query(
&query,
&[],
).unwrap();

let base_tables: Vec<String> = rows.iter().map(|row| {
let table_name: String = row.get(0);
let table_type: String = row.get(1);
if table_type == "BASE TABLE" {
table_name
} else {
Some(String::from("")).unwrap()
}
}).filter(|table_name| table_name.len() > 0).collect();

println!("Total base tables: {}", base_tables.len().to_string());
let sqlite_conn = Connection::open("twodb.db").unwrap();
create_tables_table(&sqlite_conn);

for row in rows {
println!("{}", _row_to_string(&row));
let table_name: String = row.get(1);

let mut table: Table = build_base_simple_table(table_name.clone(), database_name.clone());
table.update_self_referencing(database_name);

// check if table exists
if is_table_exists(&sqlite_conn, table_name.clone()) {

table.update_table_to_db();
continue;
}

insert_new_table(&sqlite_conn, table);
}
}
/// Get all tables that do not have foreign keys
Expand Down Expand Up @@ -166,7 +170,6 @@ pub fn update_clean_tables(database_name: &String) {

insert_new_table(&conn, table);
}
conn.close().unwrap();
}
pub fn update_empty_tables(database_name: &String) {
let mut pg_client = connect(database_name.clone()).unwrap();
Expand Down

0 comments on commit 15e562a

Please sign in to comment.