dicfg.addons.sql.write_to_database#
- write_to_database(database: Path, table: str, rows: list[dict])[source]#
Writes a list of dictionaries as rows into the specified table.
- Parameters:
database (str) – Path to the SQLite database file.
table (str) – The name of the table to write to.
rows (list of dict) – A list of dictionaries representing rows to insert, where keys are column names.
- Behavior:
If the database file does not exist, it will be created.
If the table does not exist, it will be created using the union of keys from all dictionaries. The column types are inferred from the first non-null value encountered for each key.
For each row, if a key is missing, NULL will be inserted.