Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

Independent

SQLModel Tutorial - User Guide

via Independent

Overview

Google, IBM & Meta Certificates – 40% Off
One plan covers every Professional Certificate on Coursera.
Unlock All Certificates
In this tutorial you will learn how to use SQLModel. If you need a refresher about how to use Python type hints (type annotations), check FastAPI's Python types intro. You can also check the mypy cheat sheet. SQLModel uses type annotations for everything, this way you can use a familiar Python syntax and get all the editor support possible, with autocompletion and in-editor error checking. This tutorial shows you how to use SQLModel with all its features, step by step. Each section gradually builds on the previous ones, but it's structured to separate topics, so that you can go directly to any specific one to solve your specific needs. It is also built to work as a future reference. So you can come back and see exactly what you need. All the code blocks can be copied and used directly (they are tested Python files). It is HIGHLY encouraged that you write or copy the code, edit it, and run it locally. Using it in your editor is what really shows you the benefits of SQLModel, seeing how much code it saves you, and all the editor support you get, with autocompletion and in-editor error checks, preventing lots of bugs. Running the examples is what will really help you understand what is going on. You can learn a lot more by running some examples and playing around with them than by reading all the docs here.

Syllabus

  • Create a Table with SQL
  • Create a Table with SQLModel - Use the Engine
  • Create Rows - Use the Session - INSERT
  • Automatic IDs, None Defaults, and Refreshing Data
  • Read Data - SELECT
  • Filter Data - WHERE
  • Indexes - Optimize Queries
  • Read One Row
  • Read a Range of Data - LIMIT and OFFSET
  • Update Data - UPDATE
  • Delete Data - DELETE
  • Connect Tables - JOIN - Intro
    • Create Connected Tables
    • Create and Connect Rows
    • Read Connected Data
    • Update Data Connections
    • Remove Data Connections
  • Relationship Attributes - Intro
    • Define Relationships Attributes
    • Create and Update Relationships
    • Read Relationships
    • Remove Relationships
    • Relationship back_populates
    • Cascade Delete Relationships
    • Type annotation strings
  • Many to Many - Intro
    • Create Models with a Many-to-Many Link
    • Create Data with Many-to-Many Relationships
    • Update and Remove Many-to-Many Relationships
    • Link Model with Extra Fields
  • Code Structure and Multiple Files
  • FastAPI and Pydantic - Intro
    • Simple Hero API with FastAPI
    • FastAPI Response Model with SQLModel
    • Multiple Models with FastAPI
    • Read One Model with FastAPI
    • Read Heroes with Limit and Offset with FastAPI
    • Update Data with FastAPI
    • Update with Extra Data (Hashed Passwords) with FastAPI
    • Delete Data with FastAPI
    • Session with FastAPI Dependency
    • FastAPI Path Operations for Teams - Other Models
    • Models with Relationships in FastAPI
    • Test Applications with FastAPI and SQLModel

Reviews

Start your review of SQLModel Tutorial - User Guide

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.