1
0
Fork 0
mirror of https://github.com/qurator-spk/modstool.git synced 2025-06-07 19:05:06 +02:00

🚧 Save Python types for later conversion

This commit is contained in:
Mike Gerber 2025-06-04 20:32:07 +02:00
parent 8bc443f9fb
commit 14172e3b81

View file

@ -315,7 +315,8 @@ def column_names_csv(columns):
""" """
return ",".join('"' + c + '"' for c in 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): def insert_into_db(con, table, d: Dict):
"""Insert the values from the dict into the table, creating columns if necessary""" """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) current_columns[table].append(k)
con.execute(f'ALTER TABLE {table} ADD COLUMN "{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 # Insert
# Unfortunately, Python3's sqlite3 does not like named placeholders with spaces, so we # Unfortunately, Python3's sqlite3 does not like named placeholders with spaces, so we
# have use qmark style here. # have use qmark style here.