Use of extract_table_column_map has moved to sqlhelpers.

master
voussoir 2020-02-07 15:15:49 -08:00
parent b88d577ddd
commit 92f3569971
2 changed files with 4 additions and 40 deletions

View File

@ -8,6 +8,7 @@ import string
import traceback
import warnings
from voussoirkit import sqlhelpers
from voussoirkit import winwhich
# FFmpeg ###########################################################################################
@ -190,45 +191,8 @@ CREATE INDEX IF NOT EXISTS index_tag_synonyms_name on tag_synonyms(name);
COMMIT;
'''
def _extract_table_statements(script):
for statement in script.split(';'):
if 'create table' in statement.lower():
yield statement
def _extract_table_name(create_table_statement):
# CREATE TABLE table_name(...)
table_name = create_table_statement.split('(')[0].strip()
table_name = table_name.split()[-1]
return table_name
def _extract_columns_from_table(create_table_statement):
# CREATE TABLE table_name(column_name TYPE MODIFIERS, ...)
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
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):
'''
Given an iterable, return a dictionary where the key is the item and the
value is the index. Used to convert a stringy name into the correct number
to then index into an sql row.
['test', 'toast'] -> {'test': 0, 'toast': 1}
'''
return {column: index for (index, column) in enumerate(columns)}
SQL_COLUMNS = _extract_table_column_map(DB_INIT)
SQL_INDEX = {table: _reverse_index(columns) for (table, columns) in SQL_COLUMNS.items()}
SQL_COLUMNS = sqlhelpers.extract_table_column_map(DB_INIT)
SQL_INDEX = sqlhelpers.reverse_table_column_map(SQL_COLUMNS)
ALLOWED_ORDERBY_COLUMNS = [
'extension',

View File

@ -15,4 +15,4 @@ git+https://github.com/senko/python-video-converter.git
zipstream
# My own variety toolkit.
voussoirkit>=0.0.45
voussoirkit>=0.0.46