@@ -7,16 +7,40 @@ class Advanced:
77 def __init__ (self ):
88 pass
99
10- def truncate_database (self ):
11- """Drop all tables in a database."""
12- # Get list of tables
13- tables = self .tables if isinstance (self .tables , list ) else [self .tables ]
14- if len (tables ) > 0 :
15- # Join list of tables into comma separated string
16- tables_str = ', ' .join ([wrap (table ) for table in tables ])
17- self .execute ('DROP TABLE ' + tables_str )
18- self ._printer ('\t ' + str (len (tables )), 'tables truncated' )
19- return tables
10+ # def create_table(self, table, data, headers=None):
11+ # """Generate and execute a create table query by parsing a 2D dataset"""
12+ # # TODO: Fix
13+ # # Set headers list
14+ # if not headers:
15+ # headers = data[0]
16+ #
17+ # # Create dictionary columns and data types from headers list
18+ # data_types = {header: None for header in headers}
19+ #
20+ # # Confirm that each row of the dataset is the same length
21+ # for row in data:
22+ # assert len(row) == len(headers)
23+ #
24+ # # Create list of columns
25+ # columns = [header + ' ' + data_type for header, data_type in data_types]
26+ # self._printer(columns)
27+ # statement = "create table " + table + " ("
28+ # self._printer(statement)
29+
30+ def drop_empty_tables (self ):
31+ """Drop all empty tables in a database."""
32+ # Count number of rows in each table
33+ counts = self .count_rows_all ()
34+ drops = []
35+
36+ # Loop through each table key and validate that rows count is not 0
37+ for table , count in counts .items ():
38+ if count < 1 :
39+ # Drop table if it contains no rows
40+ self .drop (table )
41+ self ._printer ('Dropped table' , table )
42+ drops .append (table )
43+ return drops
2044
2145 def insert_uniques (self , table , columns , values ):
2246 """
@@ -62,40 +86,16 @@ def update_many(self, table, columns, values, where_col, where_index):
6286 for row in values :
6387 self .update (table , columns , row , (where_col , row [where_index ]))
6488
65- # def create_table(self, table, data, headers=None):
66- # """Generate and execute a create table query by parsing a 2D dataset"""
67- # # TODO: Fix
68- # # Set headers list
69- # if not headers:
70- # headers = data[0]
71- #
72- # # Create dictionary columns and data types from headers list
73- # data_types = {header: None for header in headers}
74- #
75- # # Confirm that each row of the dataset is the same length
76- # for row in data:
77- # assert len(row) == len(headers)
78- #
79- # # Create list of columns
80- # columns = [header + ' ' + data_type for header, data_type in data_types]
81- # self._printer(columns)
82- # statement = "create table " + table + " ("
83- # self._printer(statement)
84-
85- def drop_empty_tables (self ):
86- """Drop all empty tables in a database."""
87- # Count number of rows in each table
88- counts = self .count_rows_all ()
89- drops = []
90-
91- # Loop through each table key and validate that rows count is not 0
92- for table , count in counts .items ():
93- if count < 1 :
94- # Drop table if it contains no rows
95- self .drop (table )
96- self ._printer ('Dropped table' , table )
97- drops .append (table )
98- return drops
89+ def truncate_database (self ):
90+ """Drop all tables in a database."""
91+ # Get list of tables
92+ tables = self .tables if isinstance (self .tables , list ) else [self .tables ]
93+ if len (tables ) > 0 :
94+ # Join list of tables into comma separated string
95+ tables_str = ', ' .join ([wrap (table ) for table in tables ])
96+ self .execute ('DROP TABLE ' + tables_str )
97+ self ._printer ('\t ' + str (len (tables )), 'tables truncated' )
98+ return tables
9999
100100 def execute_script (self , sql_script , commands = None ):
101101 """Wrapper method for ExecuteScript class."""
0 commit comments