Data Layer

Create SQLite tables for members, books, and loans, then seed sample rows.

Goal for this part

Create stackhaven.db with members, books, and loans tables using the standard library sqlite3 module. Seed Ada (librarian), Grace (member), sample titles, and one overdue loan for later parts.

Concepts: local SQLite for desktop apps

A desktop library keeps its database as a file next to the app. That is simpler than running a server database for classroom work. Foreign keys connect loans to members and books. Availability will be derived from open loans later—not by mutating the copies column.

CREATE TABLE books (
  id INTEGER PRIMARY KEY,
  title TEXT NOT NULL,
  author TEXT NOT NULL,
  isbn TEXT UNIQUE,
  copies INTEGER NOT NULL DEFAULT 1
);

How to run it and what you should see

Launch the snapshot. The window should report member/book/loan counts. A stackhaven.db file appears in the folder. Seed passwords use SHA-256 hashing for classroom simplicity (not a full password-manager design).