Add a function to clarify SQL_COLUMNS creation.

This commit is contained in:
voussoir 2018-11-11 19:08:31 -08:00
parent 71325f4fb5
commit d0208154e4

View file

@ -204,6 +204,14 @@ def _extract_columns_from_table(create_table_statement):
column_names = [c for c in column_names if c.lower() != 'foreign'] column_names = [c for c in column_names if c.lower() != 'foreign']
return column_names return column_names
def _extract_table_column_map(script):
columns = {}
table_statements = _extract_table_statements(script)
for table_statement in table_statements:
table_name = _extract_table_name(table_statement)
columns[table_name] = _extract_columns_from_table(table_statement)
return columns
def _reverse_index(columns): def _reverse_index(columns):
''' '''
Given an iterable, return a dictionary where the key is the item and the Given an iterable, return a dictionary where the key is the item and the
@ -213,12 +221,7 @@ def _reverse_index(columns):
''' '''
return {column: index for (index, column) in enumerate(columns)} return {column: index for (index, column) in enumerate(columns)}
SQL_COLUMNS = {} SQL_COLUMNS = _extract_table_column_map(DB_INIT)
for table_statement in _extract_table_statements(DB_INIT):
table_name = _extract_table_name(table_statement)
columns = _extract_columns_from_table(table_statement)
SQL_COLUMNS[table_name] = columns
SQL_INDEX = {table: _reverse_index(columns) for (table, columns) in SQL_COLUMNS.items()} SQL_INDEX = {table: _reverse_index(columns) for (table, columns) in SQL_COLUMNS.items()}
ALLOWED_ORDERBY_COLUMNS = [ ALLOWED_ORDERBY_COLUMNS = [