Skip to content

Instantly share code, notes, and snippets.

@prozacchiwawa
Created November 11, 2021 02:48
Show Gist options
  • Save prozacchiwawa/430fcb74aa85213b6eb7472d54f9ada7 to your computer and use it in GitHub Desktop.
Save prozacchiwawa/430fcb74aa85213b6eb7472d54f9ada7 to your computer and use it in GitHub Desktop.
very stupid sqlite schema parser
def mini_parse_schema(lines):
have_tables = {}
for line in lines:
first_paren_idx = line.index('(')
if first_paren_idx == -1:
continue
end_paren_idx = line.rindex(')')
if end_paren_idx == -1:
continue
in_parens = list(map(lambda x: x.strip().split(' '), line[first_paren_idx+1:end_paren_idx].split(',')))
create_words = list(map(lambda x: x.lower(), line[:first_paren_idx].split(' ')))
if len(create_words) == 3 and create_words[0] == 'create' and create_words[1] == 'table':
table_name = create_words[2]
table_columns = []
for coldata in in_parens:
table_columns.append(coldata[0])
have_tables[table_name] = table_columns
return have_tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment