Spaces:
Running
Running
Jon Solow
commited on
Commit
·
bf943a6
1
Parent(s):
ddf7165
Pass in commands to get df rather than getting db conn
Browse files- src/dbt_data_client.py +7 -2
- src/pages/98_Load_Data copy.py +5 -8
src/dbt_data_client.py
CHANGED
@@ -23,6 +23,11 @@ def run_dbt_build():
|
|
23 |
st.text("\n".join(stdout.decode().split("\n")[1:][:-1]))
|
24 |
|
25 |
|
26 |
-
def
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
28 |
return current_tables_df["name"].tolist()
|
|
|
23 |
st.text("\n".join(stdout.decode().split("\n")[1:][:-1]))
|
24 |
|
25 |
|
26 |
+
def execute_db_command_df(db_command: str):
|
27 |
+
with get_db_conn() as db_conn:
|
28 |
+
return db_conn.sql(db_command).df()
|
29 |
+
|
30 |
+
|
31 |
+
def get_current_tables() -> list[str]:
|
32 |
+
current_tables_df = execute_db_command_df("SHOW TABLES")
|
33 |
return current_tables_df["name"].tolist()
|
src/pages/98_Load_Data copy.py
CHANGED
@@ -3,7 +3,7 @@ import streamlit as st
|
|
3 |
from config import DEFAULT_ICON
|
4 |
from shared_page import common_page_config
|
5 |
|
6 |
-
from dbt_data_client import
|
7 |
|
8 |
|
9 |
def get_page():
|
@@ -12,15 +12,13 @@ def get_page():
|
|
12 |
common_page_config()
|
13 |
st.title(page_title)
|
14 |
|
15 |
-
with get_db_conn() as duckdb_conn:
|
16 |
-
current_tables_list = get_current_tables(duckdb_conn)
|
17 |
-
|
18 |
if st.button("Refresh Data"):
|
19 |
run_dbt_build()
|
20 |
|
|
|
|
|
21 |
if selected_table := st.selectbox("Describe a table:", current_tables_list, index=0):
|
22 |
-
|
23 |
-
describe_df = duckdb_conn.sql(f"DESCRIBE {selected_table}").df()
|
24 |
st.dataframe(
|
25 |
describe_df,
|
26 |
hide_index=True,
|
@@ -28,8 +26,7 @@ def get_page():
|
|
28 |
)
|
29 |
|
30 |
if st.checkbox("Explore data"):
|
31 |
-
|
32 |
-
st.dataframe(duckdb_conn.sql(f"SELECT * FROM {selected_table} LIMIT 50").df())
|
33 |
|
34 |
|
35 |
if __name__ == "__main__":
|
|
|
3 |
from config import DEFAULT_ICON
|
4 |
from shared_page import common_page_config
|
5 |
|
6 |
+
from dbt_data_client import run_dbt_build, get_current_tables, execute_db_command_df
|
7 |
|
8 |
|
9 |
def get_page():
|
|
|
12 |
common_page_config()
|
13 |
st.title(page_title)
|
14 |
|
|
|
|
|
|
|
15 |
if st.button("Refresh Data"):
|
16 |
run_dbt_build()
|
17 |
|
18 |
+
current_tables_list = get_current_tables()
|
19 |
+
|
20 |
if selected_table := st.selectbox("Describe a table:", current_tables_list, index=0):
|
21 |
+
describe_df = execute_db_command_df(f"DESCRIBE {selected_table}")
|
|
|
22 |
st.dataframe(
|
23 |
describe_df,
|
24 |
hide_index=True,
|
|
|
26 |
)
|
27 |
|
28 |
if st.checkbox("Explore data"):
|
29 |
+
st.dataframe(execute_db_command_df(f"SELECT * FROM {selected_table} LIMIT 50"))
|
|
|
30 |
|
31 |
|
32 |
if __name__ == "__main__":
|