Spaces:
Sleeping
Sleeping
File size: 792 Bytes
e84abc1 2a27c15 e84abc1 2a27c15 e84abc1 2a27c15 ddf7165 bf943a6 ddf7165 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import duckdb
import os
import subprocess
import streamlit as st
DBT_DIR = os.path.join(os.path.dirname(__file__), "dbt_yfdash")
DUCKDB_PATH = os.path.join(DBT_DIR, "dev.duckdb")
def get_db_conn():
return duckdb.connect(DUCKDB_PATH)
def run_dbt_build():
process = subprocess.Popen(
args=["dbt", "build"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=DBT_DIR,
)
stdout, _ = process.communicate()
st.text("\n".join(stdout.decode().split("\n")[1:][:-1]))
def execute_db_command_df(db_command: str):
with get_db_conn() as db_conn:
return db_conn.sql(db_command).df()
def get_current_tables() -> list[str]:
current_tables_df = execute_db_command_df("SHOW TABLES")
return current_tables_df["name"].tolist()
|