Skip to content
Snippets Groups Projects
Commit aa86013b authored by mjbonifa's avatar mjbonifa
Browse files

not dumped all database tables to file on export so they can be versioned

parent 4cbcdfe5
Branches
No related tags found
No related merge requests found
......@@ -186,7 +186,7 @@ def concept_set_exist(cursor, concept_set_name):
cursor.execute(query, (concept_set_name,))
# 1 if exists, 0 otherwise
return cursor.fetchone()[0] 1
return cursor.fetchone()[0] == 1
def export(map_path, export_path, version, omop_metadata):
logger.debug(f"exporting with metadata {omop_metadata} at version {version}")
......@@ -271,6 +271,20 @@ def export(map_path, export_path, version, omop_metadata):
df_out["concept_set_id"] = concept_set_id
df_out.to_sql("CONCEPT_SET_ITEM", conn, if_exists='append', index=False)
# Output all tables to CSV
# Get the list of all tables
cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cur.fetchall() # List of tables
# Export each table to a separate CSV file
for table in tables:
table_name = table[0] # Extract table name
df = pd.read_sql_query(f"SELECT * FROM {table_name}", conn)
output_file = f"{table_name}.csv"
output_path = export_path / output_file
df.to_csv(output_path, index=False) # Save as CSV
logger.info(f"Exported {table_name} to {table_name}.csv")
conn.close()
logger.debug(f"Created export db successfully")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment