On Day One, I set up the database that will hold everything my Study Buddy needs to remember (courses, materials, struggles, questions, etc.).
Today, I made the database come alive. I can now add and fetch real information like my courses and weekly materials.
- Adding Courses A course is basically the subject I’m studying (Math, Physics, CS…). I wrote a function that lets me save a new course into the database:
def add_course(name):
conn = sqlite3.connect("database.db")
c = conn.cursor()
c.execute("INSERT INTO courses (name) VALUES (?)", (name,))
conn.commit()
conn.close()
When I run add_course("Physics"), it saves Physics into my database.
Adding Weekly Materials
Next, I wanted to keep track of what I study each week. For that, I created add_material:
def add_material(course_id, week, content):
conn = sqlite3.connect("database.db")
c = conn.cursor()
c.execute(
"INSERT INTO materials (course_id, week, content) VALUES (?, ?, ?)",
(course_id, week, content)
)
conn.commit()
conn.close()
Now I can do things like:
add_material(1, 1, "Week 1 - Algebra Notes")
add_material(2, 1, "Week 1 - Intro to Programming PDF")
Fetching Courses & Materials
To confirm things are working, I also wrote simple functions to list out what’s stored:
print("Courses:", get_courses())
print("Materials for Physics:", get_materials(1))
Sample output:
Courses: [(1, 'Mathematics'), (2, 'Physics'), (3, 'Computer Science')]
Materials for Physics: [(1, 1, 'Week 1 - Algebra Notes')]
What I Learned
How to insert and fetch data from a SQLite database.
The importance of creating small helper functions (add_course, add_material) to keep my project clean and reusable.
My Study Buddy can now track multiple subjects and the weekly notes I upload.
Top comments (0)