Move column extractor to own function.

This commit is contained in:
voussoir 2018-03-18 00:21:03 -07:00
parent 4a39b527f3
commit 6add02c8a2

View file

@ -152,17 +152,21 @@ CREATE INDEX IF NOT EXISTS index_tag_synonyms_name on tag_synonyms(name);
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
'''.format(user_version=DATABASE_VERSION) '''.format(user_version=DATABASE_VERSION)
def _extract_columns(create_table_statement):
column_names = create_table_statement.split('(')[1].rsplit(')', 1)[0]
column_names = column_names.split(',')
column_names = [x.strip() for x in column_names]
column_names = [x.split(' ')[0] for x in column_names]
column_names = [c for c in column_names if c.lower() != 'foreign']
return column_names
SQL_COLUMNS = {} SQL_COLUMNS = {}
for statement in DB_INIT.split(';'): for statement in DB_INIT.split(';'):
if 'create table' not in statement.lower(): if 'create table' not in statement.lower():
continue continue
table_name = statement.split('(')[0].strip().split(' ')[-1] table_name = statement.split('(')[0].strip().split(' ')[-1]
column_names = statement.split('(')[1].rsplit(')', 1)[0] SQL_COLUMNS[table_name] = _extract_columns(statement)
column_names = column_names.split(',')
column_names = [x.strip().split(' ')[0] for x in column_names]
column_names = [c for c in column_names if c.lower() != 'foreign']
SQL_COLUMNS[table_name] = column_names
def _sql_dictify(columns): def _sql_dictify(columns):
''' '''