File size: 500 Bytes
67e3963
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

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