subject.py 785 B

1234567891011121314151617181920212223
  1. """subject model"""
  2. import streamlit as st
  3. from sqlalchemy.sql import text
  4. def create_table(conn):
  5. with conn.session as s:
  6. s.execute(text('CREATE TABLE IF NOT EXISTS subject (name TEXT, gender TEXT, birthday DATE, create_time DATETIME);'))
  7. s.commit()
  8. def get_subjects(conn):
  9. subjects = conn.query('select * from subject', ttl=0.05)
  10. return subjects
  11. def create_subject(conn, subject_form):
  12. with conn.session as s:
  13. s.execute(
  14. text('INSERT INTO subject (name, gender, birthday, create_time) VALUES (:name, :gender, :birthday, :create_time);'),
  15. params=dict(name=subject_form['name'], gender=subject_form['gender'], birthday=subject_form['birthday'], create_time=subject_form['create_time'])
  16. )
  17. s.commit()