-
Notifications
You must be signed in to change notification settings - Fork 160
/
streamlit_app.py
36 lines (28 loc) · 959 Bytes
/
streamlit_app.py
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
35
36
import os
import streamlit as st
import snowflake.connector #upm package(snowflake-connector-python==2.7.0)
# Initialize connection, using st.experimental_singleton to only run once.
@st.experimental_singleton
def init_connection():
con = snowflake.connector.connect(
user=os.getenv("SFUSER"),
password=os.getenv("PASSWORD"),
account=os.getenv("ACCOUNT"),
role=os.getenv("ROLE"),
warehouse=os.getenv("WAREHOUSE"),
)
return con
# Perform query, using st.experimental_memo to only rerun when the query changes or after 10 min.
@st.experimental_memo(ttl=600)
def run_query(query):
with conn.cursor() as cur:
cur.execute(query)
# return cur.fetch_pandas_all()
return cur.fetchall()
# rows = run_query("SHOW TABLES;")
conn = init_connection()
query = "CREATE OR REPLACE DATABASE EMPLOYEES;"
rows = run_query(query)
# Print results.
for row in rows:
st.write(row)