初始渲染页面

This commit is contained in:
leo
2024-03-06 20:53:55 +08:00
parent 721e950eb9
commit ff1d50bc3b
4 changed files with 45 additions and 45 deletions

27
main.py
View File

@@ -1,22 +1,13 @@
# streamlit_app.py
import pandas as pd
import streamlit as st
# Create the SQL connection to pets_db as specified in your secrets file.
conn = st.connection('data_db', type='sql')
from bak.init_data import BatchDataRead
from db_utils import BatchData, session
# Insert some data with conn.session.
with conn.session as s:
s.execute('CREATE TABLE IF NOT EXISTS pet_owners (person TEXT, pet TEXT);')
s.execute('DELETE FROM pet_owners;')
pet_owners = {'jerry': 'fish', 'barbara': 'cat', 'alex': 'puppy'}
for k in pet_owners:
s.execute(
'INSERT INTO pet_owners (person, pet) VALUES (:owner, :pet);',
params=dict(owner=k, pet=pet_owners[k])
)
s.commit()
# Query and display the data you inserted
pet_owners = conn.query('select * from pet_owners')
st.dataframe(pet_owners)
df = pd.DataFrame(
data=(BatchDataRead.from_orm(db_obj).dict()
for db_obj in session.query(BatchData).all())
)
#
st.dataframe(df, use_container_width=True)