med-tracker / database.py
dizzafizza1's picture
Create database.py
3df77f9 verified
raw
history blame contribute delete
990 Bytes
# database.py
import sqlite3
def init_db():
conn = sqlite3.connect('medications.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS medications (
id INTEGER PRIMARY KEY,
medication_name TEXT NOT NULL,
dosage TEXT NOT NULL,
time_of_day TEXT NOT NULL,
date TEXT NOT NULL
)
''')
conn.commit()
conn.close()
def add_medication(medication_name, dosage, time_of_day, date):
conn = sqlite3.connect('medications.db')
cursor = conn.cursor()
cursor.execute('''
INSERT INTO medications (medication_name, dosage, time_of_day, date)
VALUES (?, ?, ?, ?)
''', (medication_name, dosage, time_of_day, date))
conn.commit()
conn.close()
def get_all_medications():
conn = sqlite3.connect('medications.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM medications')
rows = cursor.fetchall()
conn.close()
return rows