Spaces:
Sleeping
Sleeping
Download db_connector.py from mgbam/BizIntel_AI: direct link, hf CLI and curl.
- Browser
- Download file 500 Bytes
-
https://huggingface.co/spaces/mgbam/BizIntel_AI/resolve/773f0cfdfef56f3cebc157dd3065acdd3c40fa45/db_connector.py
- Command line
-
hf download hf://spaces/mgbam/BizIntel_AI@773f0cfdfef56f3cebc157dd3065acdd3c40fa45/db_connector.py
-
curl -L -o db_connector.py https://huggingface.co/spaces/mgbam/BizIntel_AI/resolve/773f0cfdfef56f3cebc157dd3065acdd3c40fa45/db_connector.py
500 Bytes
| import pandas as pd | |
| from sqlalchemy import create_engine, inspect | |
| SUPPORTED_ENGINES = ["SQLite", "PostgreSQL", "MySQL", "MSSQL", "Oracle"] | |
| def list_tables(conn_str): | |
| engine = create_engine(conn_str) | |
| inspector = inspect(engine) | |
| return inspector.get_table_names() | |
| def fetch_data_from_db(conn_str, table): | |
| engine = create_engine(conn_str) | |
| df = pd.read_sql_table(table, engine) | |
| csv_path = f"data/{table}_extracted.csv" | |
| df.to_csv(csv_path, index=False) | |
| return csv_path | |