CMU 15-113: Effective Coding with AI
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:
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").
Your app needs some kind of interactive user interface. You have three options, in order from simplest to most ambitious:
README.md and located at the repository root (or inside the project folder if you placed the project in your portfolio repo). Include the following:
prompt_log.txt or prompt_log.md, and located in the same folder as your README. It must list which AI model(s)/tools you used, document the development process from start to finish, and include important, non-trivial prompts (not just summaries). As a whole, this file should make it obvious that you invested roughly 3 hours of work.| 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:
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!
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.
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:
INTEGER — whole numbers (good for id, rating, quantity)TEXT — strings (good for names, descriptions, dates as text)REAL — decimal numbers (good for prices, distances)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.
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.
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:
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?").
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.
Document your work as described in the requirements above (see "What you must submit").
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.
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.
my_tracker.db). No server setup required—it's built right into Python.INSERT INTO table (columns) VALUES (values) — adds a new recordSELECT columns FROM table WHERE condition — retrieves recordsUPDATE table SET column = value WHERE condition — modifies recordsDELETE FROM table WHERE condition — removes recordsid INTEGER PRIMARY KEY).? placeholders instead of string formatting to prevent SQL injection attacks. Example: cursor.execute("SELECT * FROM books WHERE author = ?", (author_name,))WHERE date_finished > '2026-01-01' will behave as you'd expect. If you use a different format (e.g. "March 8, 2026"), date comparisons and sorting will silently produce wrong results.WHERE notes != 'boring' will not return rows where notes is NULL, because any comparison with NULL yields NULL, not TRUE or FALSE. Use WHERE notes IS NULL or WHERE notes IS NOT NULL to check for missing values explicitly.? placeholders rather than f-strings or string concatenation when putting user input into SQL. This prevents SQL injection and avoids bugs with special characters. AI might sometimes generate code that uses f-strings in SQL—watch out for this and fix it.conn.commit(). After INSERT, UPDATE, or DELETE operations, you need to call conn.commit() to save changes to the database file. SELECT queries don't need a commit..db file and see your tables and data visually. This is great for debugging.conn.close() to cleanly close the database connection. (Note: There are ways to use Python's with statement for automatic cleanup, and you may see this in AI-generated code. If done correctly, this approach is fine too; just be consistent.)*.db to your .gitignore so it isn't pushed to GitHub. (Include a note in your README about how the database is created on first run.)