subject.py 741 B

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