From 6f8fdab8ae9db02e1268d15160c0e2cefb8194a2 Mon Sep 17 00:00:00 2001 From: Omar Agiez Date: Fri, 25 Oct 2024 23:23:01 +0300 Subject: [PATCH] Convert column names to snake_case in create_table function - Updated the create_table function to convert column names from camelCase to snake_case before creating the SQLite table. - Included a new import for the camel_to_snake function to handle the conversion. --- src/scribe_data/load/data_to_sqlite.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/scribe_data/load/data_to_sqlite.py b/src/scribe_data/load/data_to_sqlite.py index 1be35b28..71b46cf2 100644 --- a/src/scribe_data/load/data_to_sqlite.py +++ b/src/scribe_data/load/data_to_sqlite.py @@ -30,6 +30,7 @@ from tqdm.auto import tqdm +from scribe_data.cli.convert import camel_to_snake from scribe_data.utils import ( DEFAULT_JSON_EXPORT_DIR, DEFAULT_SQLITE_EXPORT_DIR, @@ -108,11 +109,14 @@ def create_table(data_type, cols): Parameters ---------- data_type : str - The name of the table to be created + The name of the table to be created. cols : list of strings - The names of columns for the new table + The names of columns for the new table. """ + # Convert column names to snake_case + cols = [camel_to_snake(col) for col in cols] + cursor.execute( f"CREATE TABLE IF NOT EXISTS {data_type} ({' Text, '.join(cols)} Text, UNIQUE({cols[0]}))" )