Week 8: Introduction to SQLModel
Due: Wednesday, Oct 14th
Exam 1 is Tuesday, so start this reading after the exam. Thursday's class writes queries with SQLModel, and HW4 follows the week after.
Prompt
Paste the standard prompt, then paste this block.
Topic: Object-relational mapping with SQLModel.
My learning objectives:
- Explain what an ORM does, and what writing one by hand would
otherwise require.
- Define a SQLModel class that corresponds to a database table.
- Insert and read objects using a Session, and explain what the
Session is doing.
Show me where this lives in the documentation. Tell me what the
official docs call each thing and roughly where to find it, and
give me search terms, rather than explaining everything yourself.
Sources
- Database to Code (ORMs) in the SQLModel documentation. Read this first; it explains the idea before any code appears.
- Tutorial in the same documentation. Work through creating a table, creating rows, and reading data.
Version drift
SQLModel is younger than most of the code an assistant was trained on, and assistants often produce SQLAlchemy code when you ask for SQLModel. The two libraries are related but the syntax differs. If what you are shown does not match the SQLModel documentation, trust the documentation.