HW6: Build a Database App

CMU 15-113: Effective Coding with AI

Due Date: Sat. 3/14 at 8:00 PM
Time Estimate: ~3 hours
Deliverables: Code + README + prompt log on GitHub, brief form response + video

Assignment Overview

Goal: Build a small app that uses a SQLite database to store, retrieve, update, and delete data. You'll choose something personally interesting to track and build a working app around it using Python and AI tools.

Why This Matters: Almost every real-world application stores data in a database. Understanding how to create tables, insert records, query data, and modify entries is a foundational skill. In this assignment you'll learn to use SQL (Structured Query Language) to manage persistent data, and you'll see how AI tools can help you learn a new technology quickly.

Examples of what you might build:

Build on prior work if you want! This assignment is designed as a fresh, standalone project that runs locally on your machine (and this will probably be the easiest path). However, if you'd prefer to add or improve database functionality to an existing project, that's perfectly fine—as long as your submission meets all the requirements below and as long as your git commits show your efforts this week.

Requirements & Scoring

Core Requirements (your app must do all of these)

Your app must use a SQLite database with at least one table containing at least 4 columns (including an id column). Your app must support all four CRUD operations:

Operation What It Means Example
Create Add a new record to the database Add a new book to my reading log
Read Retrieve and display records Show all books I've read this year
Update Modify an existing record Change a book's rating from 3 to 4 stars
Delete Remove a record from the database Remove a book I added by mistake

Your Read functionality must include at least one query that filters or sorts the data based on user input (e.g., "show only 5-star books" or "show entries sorted by date").

Interface

Your app needs some kind of interactive user interface. You have three options, in order from simplest to most ambitious:

  1. Command-line interface (CLI): A terminal-based menu where the user types choices and sees text output. This is the simplest option and (because this assignment is focusing on database functionality) this is perfectly sufficient for full credit.
  2. Simple web interface: A Flask app with HTML pages for viewing and managing data (similar to HW4). This gives you more practice with web development.
  3. Graphical interface: A desktop app using a library like tkinter or PyQt. Only attempt this if you're comfortable or curious.
Strongly recommended: Start with a CLI. It'll be fastest and easiest to get your database logic working and tested if you aren't simultaneously debugging a complex UI. If you finish early and want to add a web or graphical interface, go for it, but get the core database operations working first.
Also, if you get the database and CLI working and you unsuccessfully attempt a graphical interface, you should revert your code (and any edits to your README) to a working CLI version before the deadline so that you can still get full credit. Your README should let us know how to run and/or access a working version of your app.

What You Must Submit

Grading

Grade (Roughly) What We're Looking For
A (90-100) All four CRUD operations work correctly. At least one filtered/sorted query. Clean, understandable code. Thoughtful README and prompt log. Evidence of ~3 hours of effort. Some creativity in what you chose to track or how you display it.
B (80-89) All four CRUD operations work. README and prompt log present but less detailed. Functional but straightforward.
C (70-79) At least Create and Read work. Some attempt at Update or Delete. Basic README.
Below C Incomplete or non-functional submission.

Note: We've seen a few prevalent shortcuts taken in previous assignments that seem to be backfiring on people, either by producing substandard results or circumventing your learning goals. To that end, please avoid the following, and note that we may assess deductions for these:

Step-by-Step Instructions

We recommend working through these steps in order. Each step builds on the previous one, and this order will help you make steady progress rather than getting stuck debugging too many things at once. If you find that one of these steps is taking significantly longer than the time we specified here, or if you aren't confident on how to start, please ask on Ed or come to office hours!

Step 1: Choose What to Track (15 minutes)

Pick something you'd genuinely find useful or fun to track. Here are some ideas, but feel free to come up with your own:

Once you've picked a topic, write down 4–6 pieces of information (columns) you'd want to store for each entry. One of them should be an id that uniquely identifies each record.

Step 2: Design Your Database Schema (15 minutes)

Before writing any code, sketch out your table on paper, in a notes app, or by asking AI for help. For example, a reading log might look like:

Table: books
-----------------------------------------
| id | title | author | rating | date_finished | notes |
-----------------------------------------

Decide on the data type for each column. The most common SQLite types are:

AI tip: Try prompting: "I want to create a SQLite database to track [your topic]. Here are the columns I'm thinking of: [list them]. Can you help me write a CREATE TABLE statement and suggest any columns I might be missing?"

Step 3: Set Up Your Project and Create the Database (20 minutes)

Create a new folder and Python file for your project. Use Python's built-in sqlite3 module (no installation needed!) to create your database and table. Here's the general pattern:

import sqlite3

# Connect to (or create) a database file
con = sqlite3.connect('my_tracker.db')
cur = con.cursor()

# Create your table (if it doesn't already exist)
cur.execute('''
    CREATE TABLE IF NOT EXISTS books (
        id INTEGER PRIMARY KEY,
        title TEXT NOT NULL,
        author TEXT,
        rating INTEGER,
        date_finished TEXT,
        notes TEXT
    )
''')
con.commit()

Run your script and verify that the .db file is created. You can also ask AI to show you how to verify the table was created correctly.

Step 4: Implement Create (INSERT) (20 minutes)

Write a function that takes user input and inserts a new record into your table. For a CLI, this might look like asking the user for each field and then running an INSERT INTO statement. Test it by adding a few records.

AI tip: "Show me how to write a Python function that asks the user for [your fields] and inserts a new row into my [table name] table using sqlite3. Use parameterized queries to avoid SQL injection."

Step 5: Implement Read (SELECT) (20 minutes)

Write a function that retrieves records from your table and displays them nicely. Start with showing all records, then add at least one way to filter or sort. For example:

Step 6: Implement Update (UPDATE) and Delete (DELETE) (30 minutes)

Update: Let the user pick a record (by id or by selecting from a list) and change one or more of its fields. For example, updating a book's rating after re-reading it.

Delete: Let the user remove a record by id. Consider asking for confirmation before deleting ("Are you sure?").

Helpful pattern: For both Update and Delete, it's useful to first show the user the record they're about to modify or delete, so they can confirm they've selected the right one.

Step 7: Make the Interface (30 minutes)

If you're building a CLI (which we highly recommend), create a main menu loop that lets the user choose between operations, something like this:

--- My Reading Log ---
1. Add a book
2. View all books
3. Search books
4. Update a book
5. Delete a book
6. Quit

Choose an option:

If you're building a web interface, make sure each operation has a corresponding page or form.

Test the full flow: add several records, view them, update one, delete one, and verify everything works.

Step 8: Write Your README and Prompt Log (15 minutes)

Document your work as described in the requirements above (see "What you must submit").

Step 9: Record Your Video, Push to GitHub, Submit (15 minutes)

Make a short screencast (a minute or two is fine) showing yourself using the app: add an entry, view entries, search/filter, update one, and delete one. Push everything to GitHub, add it to your portfolio, and fill out the Google submission form.

Key Concepts

Here's a quick reference for the SQL and database concepts you'll need. We'll cover these in lecture, but this is here for you to refer back to.

Tips

AI tip: If you want an extra challenge, you might consider integrating an AI-powered feature that generates the queries itself... for example, instead of a CLI that has the user select from a fixed number of options, the user types something like "Give me all of the books that I've read in the last 3 months." That text gets sent to an AI with information about your database schema and it returns a runnable query. This is potentially much harder and more error-prone than you would expect, though, so proceed with extreme caution, and/or wait until Kian's lecture on Wednesday.

Useful Resources

Questions? Ask on Ed, or attend office hours!