YFDashboard / src /dbt_data_client.py
Jon Solow
Copy get_current_tables to dbt_data_client to remove incorrect dep path
ddf7165
raw
history blame
691 Bytes
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 get_current_tables(duckdb_conn=get_db_conn()) -> list[str]:
current_tables_df = duckdb_conn.sql("SHOW TABLES").df()
return current_tables_df["name"].tolist()