mirror of
https://github.com/qurator-spk/modstool.git
synced 2025-06-08 03:10:15 +02:00
🚧 Save Python types for later conversion
This commit is contained in:
parent
8bc443f9fb
commit
14172e3b81
1 changed files with 7 additions and 1 deletions
|
@ -315,7 +315,8 @@ def column_names_csv(columns):
|
|||
"""
|
||||
return ",".join('"' + c + '"' for c in columns)
|
||||
|
||||
current_columns = defaultdict(list)
|
||||
current_columns: defaultdict = defaultdict(list)
|
||||
current_columns_types: dict[dict] = defaultdict(dict)
|
||||
|
||||
def insert_into_db(con, table, d: Dict):
|
||||
"""Insert the values from the dict into the table, creating columns if necessary"""
|
||||
|
@ -334,6 +335,11 @@ def insert_into_db(con, table, d: Dict):
|
|||
current_columns[table].append(k)
|
||||
con.execute(f'ALTER TABLE {table} ADD COLUMN "{k}"')
|
||||
|
||||
# Save types
|
||||
for k in d.keys():
|
||||
if k not in current_columns_types[table]:
|
||||
current_columns_types[table][k] = type(d[k]).__name__
|
||||
|
||||
# Insert
|
||||
# Unfortunately, Python3's sqlite3 does not like named placeholders with spaces, so we
|
||||
# have use qmark style here.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue