From: Sebastián Ramírez Date: Fri, 26 Dec 2025 11:03:06 +0000 (-0800) Subject: ➖ Drop support for Python 3.8 in CI and docs (#1695) X-Git-Tag: 0.0.30~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=afc0c324cf436e40043353b8d4e1150b922ab383;p=thirdparty%2Ffastapi%2Fsqlmodel.git ➖ Drop support for Python 3.8 in CI and docs (#1695) Co-authored-by: Yurii Motov Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com> --- diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 72dff0d73..2fea4779a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,9 +30,6 @@ jobs: pydantic-version: - pydantic-v2 include: - - os: macos-latest - python-version: "3.8" - pydantic-version: pydantic-v1 - os: windows-latest python-version: "3.9" pydantic-version: pydantic-v2 diff --git a/docs/management-tasks.md b/docs/management-tasks.md index f8deb992f..1ca3765c0 100644 --- a/docs/management-tasks.md +++ b/docs/management-tasks.md @@ -90,7 +90,7 @@ A PR should have a specific use case that it is solving. * If the PR is for a feature, it should have docs. * Unless it's a feature we want to discourage, like support for a corner case that we don't want users to use. * The docs should include a source example file, not write Python directly in Markdown. -* If the source example(s) file can have different syntax for Python 3.8, 3.9, 3.10, there should be different versions of the file, and they should be shown in tabs in the docs. +* If the source example(s) file can have different syntax for different Python versions, there should be different versions of the file, and they should be shown in tabs in the docs. * There should be tests testing the source example. * Before the PR is applied, the new tests should fail. * After applying the PR, the new tests should pass. diff --git a/docs/tutorial/automatic-id-none-refresh.md b/docs/tutorial/automatic-id-none-refresh.md index 0e67633de..93842c690 100644 --- a/docs/tutorial/automatic-id-none-refresh.md +++ b/docs/tutorial/automatic-id-none-refresh.md @@ -342,10 +342,10 @@ And as we created the **engine** with `echo=True`, we can see the SQL statements //// -//// tab | Python 3.8+ +//// tab | Python 3.9+ ```Python -{!./docs_src/tutorial/automatic_id_none_refresh/tutorial002.py!} +{!./docs_src/tutorial/automatic_id_none_refresh/tutorial002_py39.py!} ``` {!./docs_src/tutorial/automatic_id_none_refresh/annotations/en/tutorial002.md!} diff --git a/docs/tutorial/code-structure.md b/docs/tutorial/code-structure.md index 6e377b89e..08a416542 100644 --- a/docs/tutorial/code-structure.md +++ b/docs/tutorial/code-structure.md @@ -67,9 +67,7 @@ We can use these relative imports because, for example, in the file `app.py` (th You could put all the database Models in a single Python module (a single Python file), for example `models.py`: -```Python -{!./docs_src/tutorial/code_structure/tutorial001/models.py!} -``` +{* ./docs_src/tutorial/code_structure/tutorial001_py310/models.py *} This way, you wouldn't have to deal with circular imports for other models. @@ -79,9 +77,7 @@ And then you could import the models from this file/module in any other file/mod Then you could put the code creating the **engine** and the function to create all the tables (if you are not using migrations) in another file `database.py`: -```Python -{!./docs_src/tutorial/code_structure/tutorial001/database.py!} -``` +{* ./docs_src/tutorial/code_structure/tutorial001_py310/database.py *} This file would also be imported by your application code, to use the shared **engine** and to get and call the function `create_db_and_tables()`. @@ -89,9 +85,7 @@ This file would also be imported by your application code, to use the shared **e Finally, you could put the code to create the **app** in another file `app.py`: -```Python hl_lines="3-4" -{!./docs_src/tutorial/code_structure/tutorial001/app.py!} -``` +{* ./docs_src/tutorial/code_structure/tutorial001_py310/app.py hl[3:4] *} Here we import the models, the engine, and the function to create all the tables and then we can use them all internally. @@ -207,9 +201,7 @@ So, we can use it in an `if` block and import things inside the `if` block. And Using that trick of `TYPE_CHECKING` we can "import" the `Team` in `hero_model.py`: -```Python hl_lines="1 5-6 16" -{!./docs_src/tutorial/code_structure/tutorial002/hero_model.py!} -``` +{* ./docs_src/tutorial/code_structure/tutorial002_py310/hero_model.py hl[1,5:6,16] *} Have in mind that now we *have* to put the annotation of `Team` as a string: `"Team"`, so that Python doesn't have errors at runtime. @@ -217,9 +209,7 @@ Have in mind that now we *have* to put the annotation of `Team` as a string: `"T We use the same trick in the `team_model.py` file: -```Python hl_lines="1 5-6 14" -{!./docs_src/tutorial/code_structure/tutorial002/team_model.py!} -``` +{* ./docs_src/tutorial/code_structure/tutorial002_py310/team_model.py hl[1,5:6,14] *} Now we get editor support, autocompletion, inline errors, and **SQLModel** keeps working. 🎉 @@ -227,9 +217,7 @@ Now we get editor support, autocompletion, inline errors, and **SQLModel** keeps Now, just for completeness, the `app.py` file would import the models from both modules: -```Python hl_lines="4-5 10 12-14" -{!./docs_src/tutorial/code_structure/tutorial002/app.py!} -``` +{* ./docs_src/tutorial/code_structure/tutorial002_py310/app.py hl[4:5,10,12:14] *} And of course, all the tricks with `TYPE_CHECKING` and type annotations in strings are **only needed in the files with circular imports**. diff --git a/docs/tutorial/create-db-and-table.md b/docs/tutorial/create-db-and-table.md index 688567ed4..42ec60493 100644 --- a/docs/tutorial/create-db-and-table.md +++ b/docs/tutorial/create-db-and-table.md @@ -562,10 +562,10 @@ Now, let's give the code a final look: //// -//// tab | Python 3.8+ +//// tab | Python 3.9+ ```{.python .annotate} -{!./docs_src/tutorial/create_db_and_table/tutorial003.py!} +{!./docs_src/tutorial/create_db_and_table/tutorial003_py39.py!} ``` {!./docs_src/tutorial/create_db_and_table/annotations/en/tutorial003.md!} diff --git a/docs/tutorial/delete.md b/docs/tutorial/delete.md index b0eaf6788..9f494ec44 100644 --- a/docs/tutorial/delete.md +++ b/docs/tutorial/delete.md @@ -227,10 +227,10 @@ Now let's review all that code: //// -//// tab | Python 3.8+ +//// tab | Python 3.9+ ```{ .python .annotate hl_lines="72-90" } -{!./docs_src/tutorial/delete/tutorial002.py!} +{!./docs_src/tutorial/delete/tutorial002_py39.py!} ``` {!./docs_src/tutorial/delete/annotations/en/tutorial002.md!} diff --git a/docs/tutorial/fastapi/tests.md b/docs/tutorial/fastapi/tests.md index ed4f91bcd..f7fd92c9c 100644 --- a/docs/tutorial/fastapi/tests.md +++ b/docs/tutorial/fastapi/tests.md @@ -14,7 +14,7 @@ We will use the application with the hero models, but without team models, and w Now we will see how useful it is to have this session dependency. ✨ -{* ./docs_src/tutorial/fastapi/app_testing/tutorial001/main.py ln[0] *} +{* ./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/main.py ln[0] *} ## File Structure @@ -53,16 +53,16 @@ $ pip install requests pytest Let's start with a simple test, with just the basic test code we need the check that the **FastAPI** application is creating a new hero correctly. ```{ .python .annotate } -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_001.py[ln:1-7]!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/test_main_001.py[ln:1-7]!} # Some code here omitted, we will see it later 👈 -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_001.py[ln:20-24]!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/test_main_001.py[ln:20-24]!} # Some code here omitted, we will see it later 👈 -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_001.py[ln:26-32]!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/test_main_001.py[ln:26-32]!} # Code below omitted 👇 ``` -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/annotations/en/test_main_001.md!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/annotations/en/test_main_001.md!} /// tip @@ -103,14 +103,14 @@ We will override it to use a different **session** object just for the tests. That way we protect the production database and we have better control of the data we are testing. ```{ .python .annotate hl_lines="4 9-10 12 19" } -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_002.py[ln:1-7]!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/test_main_002.py[ln:1-7]!} # Some code here omitted, we will see it later 👈 -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_002.py[ln:15-32]!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/test_main_002.py[ln:15-32]!} # Code below omitted 👇 ``` -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/annotations/en/test_main_002.md!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/annotations/en/test_main_002.md!} /// tip @@ -131,10 +131,10 @@ sqlite:///testing.db So, the testing database will be in the file `testing.db`. ``` { .python .annotate hl_lines="4 8-11 13 16 33"} -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_003.py!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/test_main_003.py!} ``` -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/annotations/en/test_main_003.md!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/annotations/en/test_main_003.md!} ### Import Table Models @@ -187,12 +187,12 @@ Let's update our code to use the in-memory database. We just have to change a couple of parameters in the **engine**. ```{ .python .annotate hl_lines="3 9-13"} -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_004.py[ln:1-13]!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/test_main_004.py[ln:1-13]!} # Code below omitted 👇 ``` -{!./docs_src/tutorial/fastapi/app_testing/tutorial001/annotations/en/test_main_004.md!} +{!./docs_src/tutorial/fastapi/app_testing/tutorial001_py310/annotations/en/test_main_004.md!} /// tip @@ -235,10 +235,10 @@ You can read more about them in the SQLAlchemy documentation about Using a Memory Database in Multiple Threads - - /// diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/annotations/en/test_main_005.md b/docs_src/tutorial/fastapi/app_testing/tutorial001/annotations/en/test_main_005.md deleted file mode 100644 index 126e1f179..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/annotations/en/test_main_005.md +++ /dev/null @@ -1,41 +0,0 @@ -1. Import `pytest`. - -2. Use the `@pytest.fixture()` decorator on top of the function to tell pytest that this is a **fixture** function (equivalent to a FastAPI dependency). - - We also give it a name of `"session"`, this will be important in the testing function. - -3. Create the fixture function. This is equivalent to a FastAPI dependency function. - - In this fixture we create the custom **engine**, with the in-memory database, we create the tables, and we create the **session**. - - Then we `yield` the `session` object. - -4. The thing that we `return` or `yield` is what will be available to the test function, in this case, the `session` object. - - Here we use `yield` so that **pytest** comes back to execute "the rest of the code" in this function once the testing function is done. - - We don't have any more visible "rest of the code" after the `yield`, but we have the end of the `with` block that will close the **session**. - - By using `yield`, pytest will: - - * run the first part - * create the **session** object - * give it to the test function - * run the test function - * once the test function is done, it will continue here, right after the `yield`, and will correctly close the **session** object in the end of the `with` block. - -5. Now, in the test function, to tell **pytest** that this test wants to get the fixture, instead of declaring something like in FastAPI with: - - ```Python - session: Session = Depends(session_fixture) - ``` - - ...the way we tell pytest what is the fixture that we want is by using the **exact same name** of the fixture. - - In this case, we named it `session`, so the parameter has to be exactly named `session` for it to work. - - We also add the type annotation `session: Session` so that we can get autocompletion and inline error checks in our editor. - -6. Now in the dependency override function, we just return the same `session` object that came from outside it. - - The `session` object comes from the parameter passed to the test function, and we just re-use it and return it here in the dependency override. diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/annotations/en/test_main_006.md b/docs_src/tutorial/fastapi/app_testing/tutorial001/annotations/en/test_main_006.md deleted file mode 100644 index d44a3b67d..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/annotations/en/test_main_006.md +++ /dev/null @@ -1,23 +0,0 @@ -1. Create the new fixture named `"client"`. - -2. This **client fixture**, in turn, also requires the **session fixture**. - -3. Now we create the **dependency override** inside the client fixture. - -4. Set the **dependency override** in the `app.dependency_overrides` dictionary. - -5. Create the `TestClient` with the **FastAPI** `app`. - -6. `yield` the `TestClient` instance. - - By using `yield`, after the test function is done, pytest will come back to execute the rest of the code after `yield`. - -7. This is the cleanup code, after `yield`, and after the test function is done. - - Here we clear the dependency overrides (here it's only one) in the FastAPI `app`. - -8. Now the test function requires the **client fixture**. - - And inside the test function, the code is quite **simple**, we just use the `TestClient` to make requests to the API, check the data, and that's it. - - The fixtures take care of all the **setup** and **cleanup** code. diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/main.py b/docs_src/tutorial/fastapi/app_testing/tutorial001/main.py deleted file mode 100644 index f0a255946..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/main.py +++ /dev/null @@ -1,105 +0,0 @@ -from typing import List, Optional - -from fastapi import Depends, FastAPI, HTTPException, Query -from sqlmodel import Field, Session, SQLModel, create_engine, select - - -class HeroBase(SQLModel): - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - -class Hero(HeroBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - -class HeroCreate(HeroBase): - pass - - -class HeroPublic(HeroBase): - id: int - - -class HeroUpdate(SQLModel): - name: Optional[str] = None - secret_name: Optional[str] = None - age: Optional[int] = None - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def get_session(): - with Session(engine) as session: - yield session - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate): - db_hero = Hero.model_validate(hero) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes( - *, - session: Session = Depends(get_session), - offset: int = 0, - limit: int = Query(default=100, le=100), -): - heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() - return heroes - - -@app.get("/heroes/{hero_id}", response_model=HeroPublic) -def read_hero(*, session: Session = Depends(get_session), hero_id: int): - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - return hero - - -@app.patch("/heroes/{hero_id}", response_model=HeroPublic) -def update_hero( - *, session: Session = Depends(get_session), hero_id: int, hero: HeroUpdate -): - db_hero = session.get(Hero, hero_id) - if not db_hero: - raise HTTPException(status_code=404, detail="Hero not found") - hero_data = hero.model_dump(exclude_unset=True) - db_hero.sqlmodel_update(hero_data) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.delete("/heroes/{hero_id}") -def delete_hero(*, session: Session = Depends(get_session), hero_id: int): - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - session.delete(hero) - session.commit() - return {"ok": True} diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_extra_coverage.py b/docs_src/tutorial/fastapi/app_testing/tutorial001/test_extra_coverage.py deleted file mode 100644 index 1d8153ab9..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_extra_coverage.py +++ /dev/null @@ -1,38 +0,0 @@ -from fastapi.testclient import TestClient -from sqlalchemy import Inspector, inspect -from sqlmodel import Session, create_engine - -from . import main as app_mod -from .test_main import client_fixture, session_fixture - -assert client_fixture, "This keeps the client fixture used below" -assert session_fixture, "This keeps the session fixture used by client_fixture" - - -def test_startup(): - app_mod.engine = create_engine("sqlite://") - app_mod.on_startup() - insp: Inspector = inspect(app_mod.engine) - assert insp.has_table(str(app_mod.Hero.__tablename__)) - - -def test_get_session(): - app_mod.engine = create_engine("sqlite://") - for session in app_mod.get_session(): - assert isinstance(session, Session) - assert session.bind == app_mod.engine - - -def test_read_hero_not_found(client: TestClient): - response = client.get("/heroes/9000") - assert response.status_code == 404 - - -def test_update_hero_not_found(client: TestClient): - response = client.patch("/heroes/9000", json={"name": "Very-Rusty-Man"}) - assert response.status_code == 404 - - -def test_delete_hero_not_found(client: TestClient): - response = client.delete("/heroes/9000") - assert response.status_code == 404 diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main.py b/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main.py deleted file mode 100644 index 435787c79..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main.py +++ /dev/null @@ -1,125 +0,0 @@ -import pytest -from fastapi.testclient import TestClient -from sqlmodel import Session, SQLModel, create_engine -from sqlmodel.pool import StaticPool - -from .main import Hero, app, get_session - - -@pytest.fixture(name="session") -def session_fixture(): - engine = create_engine( - "sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool - ) - SQLModel.metadata.create_all(engine) - with Session(engine) as session: - yield session - - -@pytest.fixture(name="client") -def client_fixture(session: Session): - def get_session_override(): - return session - - app.dependency_overrides[get_session] = get_session_override - client = TestClient(app) - yield client - app.dependency_overrides.clear() - - -def test_create_hero(client: TestClient): - response = client.post( - "/heroes/", json={"name": "Deadpond", "secret_name": "Dive Wilson"} - ) - data = response.json() - - assert response.status_code == 200 - assert data["name"] == "Deadpond" - assert data["secret_name"] == "Dive Wilson" - assert data["age"] is None - assert data["id"] is not None - - -def test_create_hero_incomplete(client: TestClient): - # No secret_name - response = client.post("/heroes/", json={"name": "Deadpond"}) - assert response.status_code == 422 - - -def test_create_hero_invalid(client: TestClient): - # secret_name has an invalid type - response = client.post( - "/heroes/", - json={ - "name": "Deadpond", - "secret_name": {"message": "Do you wanna know my secret identity?"}, - }, - ) - assert response.status_code == 422 - - -def test_read_heroes(session: Session, client: TestClient): - hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson") - hero_2 = Hero(name="Rusty-Man", secret_name="Tommy Sharp", age=48) - session.add(hero_1) - session.add(hero_2) - session.commit() - - response = client.get("/heroes/") - data = response.json() - - assert response.status_code == 200 - - assert len(data) == 2 - assert data[0]["name"] == hero_1.name - assert data[0]["secret_name"] == hero_1.secret_name - assert data[0]["age"] == hero_1.age - assert data[0]["id"] == hero_1.id - assert data[1]["name"] == hero_2.name - assert data[1]["secret_name"] == hero_2.secret_name - assert data[1]["age"] == hero_2.age - assert data[1]["id"] == hero_2.id - - -def test_read_hero(session: Session, client: TestClient): - hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson") - session.add(hero_1) - session.commit() - - response = client.get(f"/heroes/{hero_1.id}") - data = response.json() - - assert response.status_code == 200 - assert data["name"] == hero_1.name - assert data["secret_name"] == hero_1.secret_name - assert data["age"] == hero_1.age - assert data["id"] == hero_1.id - - -def test_update_hero(session: Session, client: TestClient): - hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson") - session.add(hero_1) - session.commit() - - response = client.patch(f"/heroes/{hero_1.id}", json={"name": "Deadpuddle"}) - data = response.json() - - assert response.status_code == 200 - assert data["name"] == "Deadpuddle" - assert data["secret_name"] == "Dive Wilson" - assert data["age"] is None - assert data["id"] == hero_1.id - - -def test_delete_hero(session: Session, client: TestClient): - hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson") - session.add(hero_1) - session.commit() - - response = client.delete(f"/heroes/{hero_1.id}") - - hero_in_db = session.get(Hero, hero_1.id) - - assert response.status_code == 200 - - assert hero_in_db is None diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_001.py b/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_001.py deleted file mode 100644 index 3ae40773f..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_001.py +++ /dev/null @@ -1,32 +0,0 @@ -from fastapi.testclient import TestClient -from sqlmodel import Session, SQLModel, create_engine - -from .main import app, get_session # (1)! - - -def test_create_hero(): - engine = create_engine( - "sqlite:///testing.db", connect_args={"check_same_thread": False} - ) - SQLModel.metadata.create_all(engine) - - with Session(engine) as session: - - def get_session_override(): - return session - - app.dependency_overrides[get_session] = get_session_override - - client = TestClient(app) # (2)! - - response = client.post( # (3)! - "/heroes/", json={"name": "Deadpond", "secret_name": "Dive Wilson"} - ) - app.dependency_overrides.clear() - data = response.json() # (4)! - - assert response.status_code == 200 # (5)! - assert data["name"] == "Deadpond" # (6)! - assert data["secret_name"] == "Dive Wilson" # (7)! - assert data["age"] is None # (8)! - assert data["id"] is not None # (9)! diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_002.py b/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_002.py deleted file mode 100644 index 727580b68..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_002.py +++ /dev/null @@ -1,32 +0,0 @@ -from fastapi.testclient import TestClient -from sqlmodel import Session, SQLModel, create_engine - -from .main import app, get_session # (1)! - - -def test_create_hero(): - engine = create_engine( - "sqlite:///testing.db", connect_args={"check_same_thread": False} - ) - SQLModel.metadata.create_all(engine) - - with Session(engine) as session: - - def get_session_override(): # (2)! - return session # (3)! - - app.dependency_overrides[get_session] = get_session_override # (4)! - - client = TestClient(app) - - response = client.post( - "/heroes/", json={"name": "Deadpond", "secret_name": "Dive Wilson"} - ) - app.dependency_overrides.clear() # (5)! - data = response.json() - - assert response.status_code == 200 - assert data["name"] == "Deadpond" - assert data["secret_name"] == "Dive Wilson" - assert data["age"] is None - assert data["id"] is not None diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_003.py b/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_003.py deleted file mode 100644 index 465c52510..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_003.py +++ /dev/null @@ -1,33 +0,0 @@ -from fastapi.testclient import TestClient -from sqlmodel import Session, SQLModel, create_engine - -from .main import app, get_session # (1)! - - -def test_create_hero(): - engine = create_engine( # (2)! - "sqlite:///testing.db", connect_args={"check_same_thread": False} - ) - SQLModel.metadata.create_all(engine) # (3)! - - with Session(engine) as session: # (4)! - - def get_session_override(): - return session # (5)! - - app.dependency_overrides[get_session] = get_session_override # (4)! - - client = TestClient(app) - - response = client.post( - "/heroes/", json={"name": "Deadpond", "secret_name": "Dive Wilson"} - ) - app.dependency_overrides.clear() - data = response.json() - - assert response.status_code == 200 - assert data["name"] == "Deadpond" - assert data["secret_name"] == "Dive Wilson" - assert data["age"] is None - assert data["id"] is not None - # (6)! diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_004.py b/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_004.py deleted file mode 100644 index b770a9aa5..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_004.py +++ /dev/null @@ -1,35 +0,0 @@ -from fastapi.testclient import TestClient -from sqlmodel import Session, SQLModel, create_engine -from sqlmodel.pool import StaticPool # (1)! - -from .main import app, get_session - - -def test_create_hero(): - engine = create_engine( - "sqlite://", # (2)! - connect_args={"check_same_thread": False}, - poolclass=StaticPool, # (3)! - ) - SQLModel.metadata.create_all(engine) - - with Session(engine) as session: - - def get_session_override(): - return session - - app.dependency_overrides[get_session] = get_session_override - - client = TestClient(app) - - response = client.post( - "/heroes/", json={"name": "Deadpond", "secret_name": "Dive Wilson"} - ) - app.dependency_overrides.clear() - data = response.json() - - assert response.status_code == 200 - assert data["name"] == "Deadpond" - assert data["secret_name"] == "Dive Wilson" - assert data["age"] is None - assert data["id"] is not None diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_005.py b/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_005.py deleted file mode 100644 index f653eef7e..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_005.py +++ /dev/null @@ -1,37 +0,0 @@ -import pytest # (1)! -from fastapi.testclient import TestClient -from sqlmodel import Session, SQLModel, create_engine -from sqlmodel.pool import StaticPool - -from .main import app, get_session - - -@pytest.fixture(name="session") # (2)! -def session_fixture(): # (3)! - engine = create_engine( - "sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool - ) - SQLModel.metadata.create_all(engine) - with Session(engine) as session: - yield session # (4)! - - -def test_create_hero(session: Session): # (5)! - def get_session_override(): - return session # (6)! - - app.dependency_overrides[get_session] = get_session_override - - client = TestClient(app) - - response = client.post( - "/heroes/", json={"name": "Deadpond", "secret_name": "Dive Wilson"} - ) - app.dependency_overrides.clear() - data = response.json() - - assert response.status_code == 200 - assert data["name"] == "Deadpond" - assert data["secret_name"] == "Dive Wilson" - assert data["age"] is None - assert data["id"] is not None diff --git a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_006.py b/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_006.py deleted file mode 100644 index 8dbfd45ca..000000000 --- a/docs_src/tutorial/fastapi/app_testing/tutorial001/test_main_006.py +++ /dev/null @@ -1,41 +0,0 @@ -import pytest -from fastapi.testclient import TestClient -from sqlmodel import Session, SQLModel, create_engine -from sqlmodel.pool import StaticPool - -from .main import app, get_session - - -@pytest.fixture(name="session") -def session_fixture(): - engine = create_engine( - "sqlite://", connect_args={"check_same_thread": False}, poolclass=StaticPool - ) - SQLModel.metadata.create_all(engine) - with Session(engine) as session: - yield session - - -@pytest.fixture(name="client") # (1)! -def client_fixture(session: Session): # (2)! - def get_session_override(): # (3)! - return session - - app.dependency_overrides[get_session] = get_session_override # (4)! - - client = TestClient(app) # (5)! - yield client # (6)! - app.dependency_overrides.clear() # (7)! - - -def test_create_hero(client: TestClient): # (8)! - response = client.post( - "/heroes/", json={"name": "Deadpond", "secret_name": "Dive Wilson"} - ) - data = response.json() - - assert response.status_code == 200 - assert data["name"] == "Deadpond" - assert data["secret_name"] == "Dive Wilson" - assert data["age"] is None - assert data["id"] is not None diff --git a/docs_src/tutorial/fastapi/delete/tutorial001.py b/docs_src/tutorial/fastapi/delete/tutorial001.py deleted file mode 100644 index 977882c4c..000000000 --- a/docs_src/tutorial/fastapi/delete/tutorial001.py +++ /dev/null @@ -1,98 +0,0 @@ -from typing import List, Optional - -from fastapi import FastAPI, HTTPException, Query -from sqlmodel import Field, Session, SQLModel, create_engine, select - - -class HeroBase(SQLModel): - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - -class Hero(HeroBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - -class HeroCreate(HeroBase): - pass - - -class HeroPublic(HeroBase): - id: int - - -class HeroUpdate(SQLModel): - name: Optional[str] = None - secret_name: Optional[str] = None - age: Optional[int] = None - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(hero: HeroCreate): - with Session(engine) as session: - db_hero = Hero.model_validate(hero) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)): - with Session(engine) as session: - heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() - return heroes - - -@app.get("/heroes/{hero_id}", response_model=HeroPublic) -def read_hero(hero_id: int): - with Session(engine) as session: - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - return hero - - -@app.patch("/heroes/{hero_id}", response_model=HeroPublic) -def update_hero(hero_id: int, hero: HeroUpdate): - with Session(engine) as session: - db_hero = session.get(Hero, hero_id) - if not db_hero: - raise HTTPException(status_code=404, detail="Hero not found") - hero_data = hero.model_dump(exclude_unset=True) - db_hero.sqlmodel_update(hero_data) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.delete("/heroes/{hero_id}") -def delete_hero(hero_id: int): - with Session(engine) as session: - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - session.delete(hero) - session.commit() - return {"ok": True} diff --git a/docs_src/tutorial/fastapi/limit_and_offset/tutorial001.py b/docs_src/tutorial/fastapi/limit_and_offset/tutorial001.py deleted file mode 100644 index ccf3d7703..000000000 --- a/docs_src/tutorial/fastapi/limit_and_offset/tutorial001.py +++ /dev/null @@ -1,67 +0,0 @@ -from typing import List, Optional - -from fastapi import FastAPI, HTTPException, Query -from sqlmodel import Field, Session, SQLModel, create_engine, select - - -class HeroBase(SQLModel): - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - -class Hero(HeroBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - -class HeroCreate(HeroBase): - pass - - -class HeroPublic(HeroBase): - id: int - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(hero: HeroCreate): - with Session(engine) as session: - db_hero = Hero.model_validate(hero) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)): - with Session(engine) as session: - heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() - return heroes - - -@app.get("/heroes/{hero_id}", response_model=HeroPublic) -def read_hero(hero_id: int): - with Session(engine) as session: - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - return hero diff --git a/docs_src/tutorial/fastapi/multiple_models/tutorial001.py b/docs_src/tutorial/fastapi/multiple_models/tutorial001.py deleted file mode 100644 index 42ac8051b..000000000 --- a/docs_src/tutorial/fastapi/multiple_models/tutorial001.py +++ /dev/null @@ -1,60 +0,0 @@ -from typing import List, Optional - -from fastapi import FastAPI -from sqlmodel import Field, Session, SQLModel, create_engine, select - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - -class HeroCreate(SQLModel): - name: str - secret_name: str - age: Optional[int] = None - - -class HeroPublic(SQLModel): - id: int - name: str - secret_name: str - age: Optional[int] = None - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(hero: HeroCreate): - with Session(engine) as session: - db_hero = Hero.model_validate(hero) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes(): - with Session(engine) as session: - heroes = session.exec(select(Hero)).all() - return heroes diff --git a/docs_src/tutorial/fastapi/multiple_models/tutorial002.py b/docs_src/tutorial/fastapi/multiple_models/tutorial002.py deleted file mode 100644 index 79c71f1a2..000000000 --- a/docs_src/tutorial/fastapi/multiple_models/tutorial002.py +++ /dev/null @@ -1,58 +0,0 @@ -from typing import List, Optional - -from fastapi import FastAPI -from sqlmodel import Field, Session, SQLModel, create_engine, select - - -class HeroBase(SQLModel): - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - -class Hero(HeroBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - -class HeroCreate(HeroBase): - pass - - -class HeroPublic(HeroBase): - id: int - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(hero: HeroCreate): - with Session(engine) as session: - db_hero = Hero.model_validate(hero) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes(): - with Session(engine) as session: - heroes = session.exec(select(Hero)).all() - return heroes diff --git a/docs_src/tutorial/fastapi/read_one/tutorial001.py b/docs_src/tutorial/fastapi/read_one/tutorial001.py deleted file mode 100644 index a39945173..000000000 --- a/docs_src/tutorial/fastapi/read_one/tutorial001.py +++ /dev/null @@ -1,67 +0,0 @@ -from typing import List, Optional - -from fastapi import FastAPI, HTTPException -from sqlmodel import Field, Session, SQLModel, create_engine, select - - -class HeroBase(SQLModel): - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - -class Hero(HeroBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - -class HeroCreate(HeroBase): - pass - - -class HeroPublic(HeroBase): - id: int - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(hero: HeroCreate): - with Session(engine) as session: - db_hero = Hero.model_validate(hero) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes(): - with Session(engine) as session: - heroes = session.exec(select(Hero)).all() - return heroes - - -@app.get("/heroes/{hero_id}", response_model=HeroPublic) -def read_hero(hero_id: int): - with Session(engine) as session: - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - return hero diff --git a/docs_src/tutorial/fastapi/relationships/tutorial001.py b/docs_src/tutorial/fastapi/relationships/tutorial001.py deleted file mode 100644 index 59b44730b..000000000 --- a/docs_src/tutorial/fastapi/relationships/tutorial001.py +++ /dev/null @@ -1,199 +0,0 @@ -from typing import List, Optional - -from fastapi import Depends, FastAPI, HTTPException, Query -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class TeamBase(SQLModel): - name: str = Field(index=True) - headquarters: str - - -class Team(TeamBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class TeamCreate(TeamBase): - pass - - -class TeamPublic(TeamBase): - id: int - - -class TeamUpdate(SQLModel): - id: Optional[int] = None - name: Optional[str] = None - headquarters: Optional[str] = None - - -class HeroBase(SQLModel): - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - - -class Hero(HeroBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - team: Optional[Team] = Relationship(back_populates="heroes") - - -class HeroPublic(HeroBase): - id: int - - -class HeroCreate(HeroBase): - pass - - -class HeroUpdate(SQLModel): - name: Optional[str] = None - secret_name: Optional[str] = None - age: Optional[int] = None - team_id: Optional[int] = None - - -class HeroPublicWithTeam(HeroPublic): - team: Optional[TeamPublic] = None - - -class TeamPublicWithHeroes(TeamPublic): - heroes: List[HeroPublic] = [] - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def get_session(): - with Session(engine) as session: - yield session - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate): - db_hero = Hero.model_validate(hero) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes( - *, - session: Session = Depends(get_session), - offset: int = 0, - limit: int = Query(default=100, le=100), -): - heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() - return heroes - - -@app.get("/heroes/{hero_id}", response_model=HeroPublicWithTeam) -def read_hero(*, session: Session = Depends(get_session), hero_id: int): - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - return hero - - -@app.patch("/heroes/{hero_id}", response_model=HeroPublic) -def update_hero( - *, session: Session = Depends(get_session), hero_id: int, hero: HeroUpdate -): - db_hero = session.get(Hero, hero_id) - if not db_hero: - raise HTTPException(status_code=404, detail="Hero not found") - hero_data = hero.model_dump(exclude_unset=True) - db_hero.sqlmodel_update(hero_data) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.delete("/heroes/{hero_id}") -def delete_hero(*, session: Session = Depends(get_session), hero_id: int): - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - session.delete(hero) - session.commit() - return {"ok": True} - - -@app.post("/teams/", response_model=TeamPublic) -def create_team(*, session: Session = Depends(get_session), team: TeamCreate): - db_team = Team.model_validate(team) - session.add(db_team) - session.commit() - session.refresh(db_team) - return db_team - - -@app.get("/teams/", response_model=List[TeamPublic]) -def read_teams( - *, - session: Session = Depends(get_session), - offset: int = 0, - limit: int = Query(default=100, le=100), -): - teams = session.exec(select(Team).offset(offset).limit(limit)).all() - return teams - - -@app.get("/teams/{team_id}", response_model=TeamPublicWithHeroes) -def read_team(*, team_id: int, session: Session = Depends(get_session)): - team = session.get(Team, team_id) - if not team: - raise HTTPException(status_code=404, detail="Team not found") - return team - - -@app.patch("/teams/{team_id}", response_model=TeamPublic) -def update_team( - *, - session: Session = Depends(get_session), - team_id: int, - team: TeamUpdate, -): - db_team = session.get(Team, team_id) - if not db_team: - raise HTTPException(status_code=404, detail="Team not found") - team_data = team.model_dump(exclude_unset=True) - db_team.sqlmodel_update(team_data) - session.add(db_team) - session.commit() - session.refresh(db_team) - return db_team - - -@app.delete("/teams/{team_id}") -def delete_team(*, session: Session = Depends(get_session), team_id: int): - team = session.get(Team, team_id) - if not team: - raise HTTPException(status_code=404, detail="Team not found") - session.delete(team) - session.commit() - return {"ok": True} diff --git a/docs_src/tutorial/fastapi/response_model/tutorial001.py b/docs_src/tutorial/fastapi/response_model/tutorial001.py deleted file mode 100644 index 57d873839..000000000 --- a/docs_src/tutorial/fastapi/response_model/tutorial001.py +++ /dev/null @@ -1,46 +0,0 @@ -from typing import List, Optional - -from fastapi import FastAPI -from sqlmodel import Field, Session, SQLModel, create_engine, select - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=Hero) -def create_hero(hero: Hero): - with Session(engine) as session: - session.add(hero) - session.commit() - session.refresh(hero) - return hero - - -@app.get("/heroes/", response_model=List[Hero]) -def read_heroes(): - with Session(engine) as session: - heroes = session.exec(select(Hero)).all() - return heroes diff --git a/docs_src/tutorial/fastapi/session_with_dependency/tutorial001.py b/docs_src/tutorial/fastapi/session_with_dependency/tutorial001.py deleted file mode 100644 index f0a255946..000000000 --- a/docs_src/tutorial/fastapi/session_with_dependency/tutorial001.py +++ /dev/null @@ -1,105 +0,0 @@ -from typing import List, Optional - -from fastapi import Depends, FastAPI, HTTPException, Query -from sqlmodel import Field, Session, SQLModel, create_engine, select - - -class HeroBase(SQLModel): - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - -class Hero(HeroBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - -class HeroCreate(HeroBase): - pass - - -class HeroPublic(HeroBase): - id: int - - -class HeroUpdate(SQLModel): - name: Optional[str] = None - secret_name: Optional[str] = None - age: Optional[int] = None - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def get_session(): - with Session(engine) as session: - yield session - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate): - db_hero = Hero.model_validate(hero) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes( - *, - session: Session = Depends(get_session), - offset: int = 0, - limit: int = Query(default=100, le=100), -): - heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() - return heroes - - -@app.get("/heroes/{hero_id}", response_model=HeroPublic) -def read_hero(*, session: Session = Depends(get_session), hero_id: int): - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - return hero - - -@app.patch("/heroes/{hero_id}", response_model=HeroPublic) -def update_hero( - *, session: Session = Depends(get_session), hero_id: int, hero: HeroUpdate -): - db_hero = session.get(Hero, hero_id) - if not db_hero: - raise HTTPException(status_code=404, detail="Hero not found") - hero_data = hero.model_dump(exclude_unset=True) - db_hero.sqlmodel_update(hero_data) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.delete("/heroes/{hero_id}") -def delete_hero(*, session: Session = Depends(get_session), hero_id: int): - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - session.delete(hero) - session.commit() - return {"ok": True} diff --git a/docs_src/tutorial/fastapi/simple_hero_api/tutorial001.py b/docs_src/tutorial/fastapi/simple_hero_api/tutorial001_py39.py similarity index 100% rename from docs_src/tutorial/fastapi/simple_hero_api/tutorial001.py rename to docs_src/tutorial/fastapi/simple_hero_api/tutorial001_py39.py diff --git a/docs_src/tutorial/fastapi/teams/tutorial001.py b/docs_src/tutorial/fastapi/teams/tutorial001.py deleted file mode 100644 index 49dd83065..000000000 --- a/docs_src/tutorial/fastapi/teams/tutorial001.py +++ /dev/null @@ -1,190 +0,0 @@ -from typing import List, Optional - -from fastapi import Depends, FastAPI, HTTPException, Query -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class TeamBase(SQLModel): - name: str = Field(index=True) - headquarters: str - - -class Team(TeamBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class TeamCreate(TeamBase): - pass - - -class TeamPublic(TeamBase): - id: int - - -class TeamUpdate(SQLModel): - name: Optional[str] = None - headquarters: Optional[str] = None - - -class HeroBase(SQLModel): - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - - -class Hero(HeroBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - team: Optional[Team] = Relationship(back_populates="heroes") - - -class HeroPublic(HeroBase): - id: int - - -class HeroCreate(HeroBase): - pass - - -class HeroUpdate(SQLModel): - name: Optional[str] = None - secret_name: Optional[str] = None - age: Optional[int] = None - team_id: Optional[int] = None - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def get_session(): - with Session(engine) as session: - yield session - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate): - db_hero = Hero.model_validate(hero) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes( - *, - session: Session = Depends(get_session), - offset: int = 0, - limit: int = Query(default=100, le=100), -): - heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() - return heroes - - -@app.get("/heroes/{hero_id}", response_model=HeroPublic) -def read_hero(*, session: Session = Depends(get_session), hero_id: int): - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - return hero - - -@app.patch("/heroes/{hero_id}", response_model=HeroPublic) -def update_hero( - *, session: Session = Depends(get_session), hero_id: int, hero: HeroUpdate -): - db_hero = session.get(Hero, hero_id) - if not db_hero: - raise HTTPException(status_code=404, detail="Hero not found") - hero_data = hero.model_dump(exclude_unset=True) - db_hero.sqlmodel_update(hero_data) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.delete("/heroes/{hero_id}") -def delete_hero(*, session: Session = Depends(get_session), hero_id: int): - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - session.delete(hero) - session.commit() - return {"ok": True} - - -@app.post("/teams/", response_model=TeamPublic) -def create_team(*, session: Session = Depends(get_session), team: TeamCreate): - db_team = Team.model_validate(team) - session.add(db_team) - session.commit() - session.refresh(db_team) - return db_team - - -@app.get("/teams/", response_model=List[TeamPublic]) -def read_teams( - *, - session: Session = Depends(get_session), - offset: int = 0, - limit: int = Query(default=100, le=100), -): - teams = session.exec(select(Team).offset(offset).limit(limit)).all() - return teams - - -@app.get("/teams/{team_id}", response_model=TeamPublic) -def read_team(*, team_id: int, session: Session = Depends(get_session)): - team = session.get(Team, team_id) - if not team: - raise HTTPException(status_code=404, detail="Team not found") - return team - - -@app.patch("/teams/{team_id}", response_model=TeamPublic) -def update_team( - *, - session: Session = Depends(get_session), - team_id: int, - team: TeamUpdate, -): - db_team = session.get(Team, team_id) - if not db_team: - raise HTTPException(status_code=404, detail="Team not found") - team_data = team.model_dump(exclude_unset=True) - db_team.sqlmodel_update(team_data) - session.add(db_team) - session.commit() - session.refresh(db_team) - return db_team - - -@app.delete("/teams/{team_id}") -def delete_team(*, session: Session = Depends(get_session), team_id: int): - team = session.get(Team, team_id) - if not team: - raise HTTPException(status_code=404, detail="Team not found") - session.delete(team) - session.commit() - return {"ok": True} diff --git a/docs_src/tutorial/fastapi/update/tutorial001.py b/docs_src/tutorial/fastapi/update/tutorial001.py deleted file mode 100644 index 6a02f6c01..000000000 --- a/docs_src/tutorial/fastapi/update/tutorial001.py +++ /dev/null @@ -1,87 +0,0 @@ -from typing import List, Optional - -from fastapi import FastAPI, HTTPException, Query -from sqlmodel import Field, Session, SQLModel, create_engine, select - - -class HeroBase(SQLModel): - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - -class Hero(HeroBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - - -class HeroCreate(HeroBase): - pass - - -class HeroPublic(HeroBase): - id: int - - -class HeroUpdate(SQLModel): - name: Optional[str] = None - secret_name: Optional[str] = None - age: Optional[int] = None - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(hero: HeroCreate): - with Session(engine) as session: - db_hero = Hero.model_validate(hero) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)): - with Session(engine) as session: - heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() - return heroes - - -@app.get("/heroes/{hero_id}", response_model=HeroPublic) -def read_hero(hero_id: int): - with Session(engine) as session: - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - return hero - - -@app.patch("/heroes/{hero_id}", response_model=HeroPublic) -def update_hero(hero_id: int, hero: HeroUpdate): - with Session(engine) as session: - db_hero = session.get(Hero, hero_id) - if not db_hero: - raise HTTPException(status_code=404, detail="Hero not found") - hero_data = hero.model_dump(exclude_unset=True) - db_hero.sqlmodel_update(hero_data) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero diff --git a/docs_src/tutorial/fastapi/update/tutorial002.py b/docs_src/tutorial/fastapi/update/tutorial002.py deleted file mode 100644 index c8838aeff..000000000 --- a/docs_src/tutorial/fastapi/update/tutorial002.py +++ /dev/null @@ -1,101 +0,0 @@ -from typing import List, Optional - -from fastapi import FastAPI, HTTPException, Query -from sqlmodel import Field, Session, SQLModel, create_engine, select - - -class HeroBase(SQLModel): - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - -class Hero(HeroBase, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - hashed_password: str = Field() - - -class HeroCreate(HeroBase): - password: str - - -class HeroPublic(HeroBase): - id: int - - -class HeroUpdate(SQLModel): - name: Optional[str] = None - secret_name: Optional[str] = None - age: Optional[int] = None - password: Optional[str] = None - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -connect_args = {"check_same_thread": False} -engine = create_engine(sqlite_url, echo=True, connect_args=connect_args) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def hash_password(password: str) -> str: - # Use something like passlib here - return f"not really hashed {password} hehehe" - - -app = FastAPI() - - -@app.on_event("startup") -def on_startup(): - create_db_and_tables() - - -@app.post("/heroes/", response_model=HeroPublic) -def create_hero(hero: HeroCreate): - hashed_password = hash_password(hero.password) - with Session(engine) as session: - extra_data = {"hashed_password": hashed_password} - db_hero = Hero.model_validate(hero, update=extra_data) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero - - -@app.get("/heroes/", response_model=List[HeroPublic]) -def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)): - with Session(engine) as session: - heroes = session.exec(select(Hero).offset(offset).limit(limit)).all() - return heroes - - -@app.get("/heroes/{hero_id}", response_model=HeroPublic) -def read_hero(hero_id: int): - with Session(engine) as session: - hero = session.get(Hero, hero_id) - if not hero: - raise HTTPException(status_code=404, detail="Hero not found") - return hero - - -@app.patch("/heroes/{hero_id}", response_model=HeroPublic) -def update_hero(hero_id: int, hero: HeroUpdate): - with Session(engine) as session: - db_hero = session.get(Hero, hero_id) - if not db_hero: - raise HTTPException(status_code=404, detail="Hero not found") - hero_data = hero.model_dump(exclude_unset=True) - extra_data = {} - if "password" in hero_data: - password = hero_data["password"] - hashed_password = hash_password(password) - extra_data["hashed_password"] = hashed_password - db_hero.sqlmodel_update(hero_data, update=extra_data) - session.add(db_hero) - session.commit() - session.refresh(db_hero) - return db_hero diff --git a/docs_src/tutorial/indexes/tutorial001.py b/docs_src/tutorial/indexes/tutorial001_py39.py similarity index 100% rename from docs_src/tutorial/indexes/tutorial001.py rename to docs_src/tutorial/indexes/tutorial001_py39.py diff --git a/docs_src/tutorial/indexes/tutorial002.py b/docs_src/tutorial/indexes/tutorial002_py39.py similarity index 100% rename from docs_src/tutorial/indexes/tutorial002.py rename to docs_src/tutorial/indexes/tutorial002_py39.py diff --git a/docs_src/tutorial/insert/tutorial001.py b/docs_src/tutorial/insert/tutorial001_py39.py similarity index 100% rename from docs_src/tutorial/insert/tutorial001.py rename to docs_src/tutorial/insert/tutorial001_py39.py diff --git a/docs_src/tutorial/insert/tutorial002.py b/docs_src/tutorial/insert/tutorial002_py39.py similarity index 100% rename from docs_src/tutorial/insert/tutorial002.py rename to docs_src/tutorial/insert/tutorial002_py39.py diff --git a/docs_src/tutorial/insert/tutorial003.py b/docs_src/tutorial/insert/tutorial003_py39.py similarity index 100% rename from docs_src/tutorial/insert/tutorial003.py rename to docs_src/tutorial/insert/tutorial003_py39.py diff --git a/docs_src/tutorial/many_to_many/tutorial001.py b/docs_src/tutorial/many_to_many/tutorial001.py deleted file mode 100644 index 79f9e7909..000000000 --- a/docs_src/tutorial/many_to_many/tutorial001.py +++ /dev/null @@ -1,84 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine - - -class HeroTeamLink(SQLModel, table=True): - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", primary_key=True - ) - hero_id: Optional[int] = Field( - default=None, foreign_key="hero.id", primary_key=True - ) - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="teams", link_model=HeroTeamLink) - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - teams: List[Team] = Relationship(back_populates="heroes", link_model=HeroTeamLink) - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", - secret_name="Dive Wilson", - teams=[team_z_force, team_preventers], - ) - hero_rusty_man = Hero( - name="Rusty-Man", - secret_name="Tommy Sharp", - age=48, - teams=[team_preventers], - ) - hero_spider_boy = Hero( - name="Spider-Boy", secret_name="Pedro Parqueador", teams=[team_preventers] - ) - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Deadpond:", hero_deadpond) - print("Deadpond teams:", hero_deadpond.teams) - print("Rusty-Man:", hero_rusty_man) - print("Rusty-Man Teams:", hero_rusty_man.teams) - print("Spider-Boy:", hero_spider_boy) - print("Spider-Boy Teams:", hero_spider_boy.teams) - - -def main(): - create_db_and_tables() - create_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/many_to_many/tutorial002.py b/docs_src/tutorial/many_to_many/tutorial002.py deleted file mode 100644 index 9845340ec..000000000 --- a/docs_src/tutorial/many_to_many/tutorial002.py +++ /dev/null @@ -1,107 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class HeroTeamLink(SQLModel, table=True): - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", primary_key=True - ) - hero_id: Optional[int] = Field( - default=None, foreign_key="hero.id", primary_key=True - ) - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="teams", link_model=HeroTeamLink) - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - teams: List[Team] = Relationship(back_populates="heroes", link_model=HeroTeamLink) - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", - secret_name="Dive Wilson", - teams=[team_z_force, team_preventers], - ) - hero_rusty_man = Hero( - name="Rusty-Man", - secret_name="Tommy Sharp", - age=48, - teams=[team_preventers], - ) - hero_spider_boy = Hero( - name="Spider-Boy", secret_name="Pedro Parqueador", teams=[team_preventers] - ) - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Deadpond:", hero_deadpond) - print("Deadpond teams:", hero_deadpond.teams) - print("Rusty-Man:", hero_rusty_man) - print("Rusty-Man Teams:", hero_rusty_man.teams) - print("Spider-Boy:", hero_spider_boy) - print("Spider-Boy Teams:", hero_spider_boy.teams) - - -def update_heroes(): - with Session(engine) as session: - hero_spider_boy = session.exec( - select(Hero).where(Hero.name == "Spider-Boy") - ).one() - team_z_force = session.exec(select(Team).where(Team.name == "Z-Force")).one() - - team_z_force.heroes.append(hero_spider_boy) - session.add(team_z_force) - session.commit() - - print("Updated Spider-Boy's Teams:", hero_spider_boy.teams) - print("Z-Force heroes:", team_z_force.heroes) - - hero_spider_boy.teams.remove(team_z_force) - session.add(team_z_force) - session.commit() - - print("Reverted Z-Force's heroes:", team_z_force.heroes) - print("Reverted Spider-Boy's teams:", hero_spider_boy.teams) - - -def main(): - create_db_and_tables() - create_heroes() - update_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/many_to_many/tutorial003.py b/docs_src/tutorial/many_to_many/tutorial003.py deleted file mode 100644 index 6c23878b0..000000000 --- a/docs_src/tutorial/many_to_many/tutorial003.py +++ /dev/null @@ -1,123 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class HeroTeamLink(SQLModel, table=True): - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", primary_key=True - ) - hero_id: Optional[int] = Field( - default=None, foreign_key="hero.id", primary_key=True - ) - is_training: bool = False - - team: "Team" = Relationship(back_populates="hero_links") - hero: "Hero" = Relationship(back_populates="team_links") - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - hero_links: List[HeroTeamLink] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_links: List[HeroTeamLink] = Relationship(back_populates="hero") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", - secret_name="Dive Wilson", - ) - hero_rusty_man = Hero( - name="Rusty-Man", - secret_name="Tommy Sharp", - age=48, - ) - hero_spider_boy = Hero( - name="Spider-Boy", - secret_name="Pedro Parqueador", - ) - deadpond_team_z_link = HeroTeamLink(team=team_z_force, hero=hero_deadpond) - deadpond_preventers_link = HeroTeamLink( - team=team_preventers, hero=hero_deadpond, is_training=True - ) - spider_boy_preventers_link = HeroTeamLink( - team=team_preventers, hero=hero_spider_boy, is_training=True - ) - rusty_man_preventers_link = HeroTeamLink( - team=team_preventers, hero=hero_rusty_man - ) - - session.add(deadpond_team_z_link) - session.add(deadpond_preventers_link) - session.add(spider_boy_preventers_link) - session.add(rusty_man_preventers_link) - session.commit() - - for link in team_z_force.hero_links: - print("Z-Force hero:", link.hero, "is training:", link.is_training) - - for link in team_preventers.hero_links: - print("Preventers hero:", link.hero, "is training:", link.is_training) - - -def update_heroes(): - with Session(engine) as session: - hero_spider_boy = session.exec( - select(Hero).where(Hero.name == "Spider-Boy") - ).one() - team_z_force = session.exec(select(Team).where(Team.name == "Z-Force")).one() - - spider_boy_z_force_link = HeroTeamLink( - team=team_z_force, hero=hero_spider_boy, is_training=True - ) - team_z_force.hero_links.append(spider_boy_z_force_link) - session.add(team_z_force) - session.commit() - - print("Updated Spider-Boy's Teams:", hero_spider_boy.team_links) - print("Z-Force heroes:", team_z_force.hero_links) - - for link in hero_spider_boy.team_links: - if link.team.name == "Preventers": - link.is_training = False - - session.add(hero_spider_boy) - session.commit() - - for link in hero_spider_boy.team_links: - print("Spider-Boy team:", link.team, "is training:", link.is_training) - - -def main(): - create_db_and_tables() - create_heroes() - update_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/offset_and_limit/tutorial001.py b/docs_src/tutorial/offset_and_limit/tutorial001_py39.py similarity index 100% rename from docs_src/tutorial/offset_and_limit/tutorial001.py rename to docs_src/tutorial/offset_and_limit/tutorial001_py39.py diff --git a/docs_src/tutorial/offset_and_limit/tutorial002.py b/docs_src/tutorial/offset_and_limit/tutorial002_py39.py similarity index 100% rename from docs_src/tutorial/offset_and_limit/tutorial002.py rename to docs_src/tutorial/offset_and_limit/tutorial002_py39.py diff --git a/docs_src/tutorial/offset_and_limit/tutorial003.py b/docs_src/tutorial/offset_and_limit/tutorial003_py39.py similarity index 100% rename from docs_src/tutorial/offset_and_limit/tutorial003.py rename to docs_src/tutorial/offset_and_limit/tutorial003_py39.py diff --git a/docs_src/tutorial/offset_and_limit/tutorial004.py b/docs_src/tutorial/offset_and_limit/tutorial004_py39.py similarity index 100% rename from docs_src/tutorial/offset_and_limit/tutorial004.py rename to docs_src/tutorial/offset_and_limit/tutorial004_py39.py diff --git a/docs_src/tutorial/one/tutorial001.py b/docs_src/tutorial/one/tutorial001_py39.py similarity index 100% rename from docs_src/tutorial/one/tutorial001.py rename to docs_src/tutorial/one/tutorial001_py39.py diff --git a/docs_src/tutorial/one/tutorial002.py b/docs_src/tutorial/one/tutorial002_py39.py similarity index 100% rename from docs_src/tutorial/one/tutorial002.py rename to docs_src/tutorial/one/tutorial002_py39.py diff --git a/docs_src/tutorial/one/tutorial003.py b/docs_src/tutorial/one/tutorial003_py39.py similarity index 100% rename from docs_src/tutorial/one/tutorial003.py rename to docs_src/tutorial/one/tutorial003_py39.py diff --git a/docs_src/tutorial/one/tutorial004.py b/docs_src/tutorial/one/tutorial004_py39.py similarity index 100% rename from docs_src/tutorial/one/tutorial004.py rename to docs_src/tutorial/one/tutorial004_py39.py diff --git a/docs_src/tutorial/one/tutorial005.py b/docs_src/tutorial/one/tutorial005_py39.py similarity index 100% rename from docs_src/tutorial/one/tutorial005.py rename to docs_src/tutorial/one/tutorial005_py39.py diff --git a/docs_src/tutorial/one/tutorial006.py b/docs_src/tutorial/one/tutorial006_py39.py similarity index 100% rename from docs_src/tutorial/one/tutorial006.py rename to docs_src/tutorial/one/tutorial006_py39.py diff --git a/docs_src/tutorial/one/tutorial007.py b/docs_src/tutorial/one/tutorial007_py39.py similarity index 100% rename from docs_src/tutorial/one/tutorial007.py rename to docs_src/tutorial/one/tutorial007_py39.py diff --git a/docs_src/tutorial/one/tutorial008.py b/docs_src/tutorial/one/tutorial008_py39.py similarity index 100% rename from docs_src/tutorial/one/tutorial008.py rename to docs_src/tutorial/one/tutorial008_py39.py diff --git a/docs_src/tutorial/one/tutorial009.py b/docs_src/tutorial/one/tutorial009_py39.py similarity index 100% rename from docs_src/tutorial/one/tutorial009.py rename to docs_src/tutorial/one/tutorial009_py39.py diff --git a/docs_src/tutorial/relationship_attributes/back_populates/tutorial001.py b/docs_src/tutorial/relationship_attributes/back_populates/tutorial001.py deleted file mode 100644 index 39230cb69..000000000 --- a/docs_src/tutorial/relationship_attributes/back_populates/tutorial001.py +++ /dev/null @@ -1,143 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship() - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship() - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - hero_tarantula = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32) - hero_dr_weird = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36) - hero_cap = Hero( - name="Captain North America", secret_name="Esteban Rogelios", age=93 - ) - - team_preventers.heroes.append(hero_tarantula) - team_preventers.heroes.append(hero_dr_weird) - team_preventers.heroes.append(hero_cap) - session.add(team_preventers) - session.commit() - session.refresh(hero_tarantula) - session.refresh(hero_dr_weird) - session.refresh(hero_cap) - print("Preventers new hero:", hero_tarantula) - print("Preventers new hero:", hero_dr_weird) - print("Preventers new hero:", hero_cap) - - -def select_heroes(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Preventers") - result = session.exec(statement) - team_preventers = result.one() - - print("Preventers heroes:", team_preventers.heroes) - - -def update_heroes(): - with Session(engine) as session: - hero_spider_boy = session.exec( - select(Hero).where(Hero.name == "Spider-Boy") - ).one() - - preventers_team = session.exec( - select(Team).where(Team.name == "Preventers") - ).one() - - print("Hero Spider-Boy:", hero_spider_boy) - print("Preventers Team:", preventers_team) - print("Preventers Team Heroes:", preventers_team.heroes) - - hero_spider_boy.team = None - - print("Spider-Boy without team:", hero_spider_boy) - - print("Preventers Team Heroes again:", preventers_team.heroes) - - session.add(hero_spider_boy) - session.commit() - print("After committing") - - session.refresh(hero_spider_boy) - print("Spider-Boy after commit:", hero_spider_boy) - - print("Preventers Team Heroes after commit:", preventers_team.heroes) - - -def main(): - create_db_and_tables() - create_heroes() - select_heroes() - update_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/back_populates/tutorial002.py b/docs_src/tutorial/relationship_attributes/back_populates/tutorial002.py deleted file mode 100644 index a1add4bcc..000000000 --- a/docs_src/tutorial/relationship_attributes/back_populates/tutorial002.py +++ /dev/null @@ -1,143 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - hero_tarantula = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32) - hero_dr_weird = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36) - hero_cap = Hero( - name="Captain North America", secret_name="Esteban Rogelios", age=93 - ) - - team_preventers.heroes.append(hero_tarantula) - team_preventers.heroes.append(hero_dr_weird) - team_preventers.heroes.append(hero_cap) - session.add(team_preventers) - session.commit() - session.refresh(hero_tarantula) - session.refresh(hero_dr_weird) - session.refresh(hero_cap) - print("Preventers new hero:", hero_tarantula) - print("Preventers new hero:", hero_dr_weird) - print("Preventers new hero:", hero_cap) - - -def select_heroes(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Preventers") - result = session.exec(statement) - team_preventers = result.one() - - print("Preventers heroes:", team_preventers.heroes) - - -def update_heroes(): - with Session(engine) as session: - hero_spider_boy = session.exec( - select(Hero).where(Hero.name == "Spider-Boy") - ).one() - - preventers_team = session.exec( - select(Team).where(Team.name == "Preventers") - ).one() - - print("Hero Spider-Boy:", hero_spider_boy) - print("Preventers Team:", preventers_team) - print("Preventers Team Heroes:", preventers_team.heroes) - - hero_spider_boy.team = None - - print("Spider-Boy without team:", hero_spider_boy) - - print("Preventers Team Heroes again:", preventers_team.heroes) - - session.add(hero_spider_boy) - session.commit() - print("After committing") - - session.refresh(hero_spider_boy) - print("Spider-Boy after commit:", hero_spider_boy) - - print("Preventers Team Heroes after commit:", preventers_team.heroes) - - -def main(): - create_db_and_tables() - create_heroes() - select_heroes() - update_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/back_populates/tutorial003.py b/docs_src/tutorial/relationship_attributes/back_populates/tutorial003.py deleted file mode 100644 index 98e197002..000000000 --- a/docs_src/tutorial/relationship_attributes/back_populates/tutorial003.py +++ /dev/null @@ -1,59 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, SQLModel, create_engine - - -class Weapon(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - - hero: "Hero" = Relationship(back_populates="weapon") - - -class Power(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - - hero_id: int = Field(foreign_key="hero.id") - hero: "Hero" = Relationship(back_populates="powers") - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - weapon_id: Optional[int] = Field(default=None, foreign_key="weapon.id") - weapon: Optional[Weapon] = Relationship(back_populates="hero") - - powers: List[Power] = Relationship(back_populates="hero") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def main(): - create_db_and_tables() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial001.py b/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial001.py deleted file mode 100644 index 877aeb3c6..000000000 --- a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial001.py +++ /dev/null @@ -1,110 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team", cascade_delete=True) - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", ondelete="CASCADE" - ) - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - -def delete_team(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - session.delete(team) - session.commit() - print("Deleted team:", team) - - -def select_deleted_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Black Lion") - result = session.exec(statement) - hero = result.first() - print("Black Lion not found:", hero) - - statement = select(Hero).where(Hero.name == "Princess Sure-E") - result = session.exec(statement) - hero = result.first() - print("Princess Sure-E not found:", hero) - - -def main(): - create_db_and_tables() - create_heroes() - delete_team() - select_deleted_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial002.py b/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial002.py deleted file mode 100644 index ac97a20f2..000000000 --- a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial002.py +++ /dev/null @@ -1,110 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", ondelete="SET NULL" - ) - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - -def delete_team(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - session.delete(team) - session.commit() - print("Deleted team:", team) - - -def select_deleted_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Black Lion") - result = session.exec(statement) - hero = result.first() - print("Black Lion has no team:", hero) - - statement = select(Hero).where(Hero.name == "Princess Sure-E") - result = session.exec(statement) - hero = result.first() - print("Princess Sure-E has no team:", hero) - - -def main(): - create_db_and_tables() - create_heroes() - delete_team() - select_deleted_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial003.py b/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial003.py deleted file mode 100644 index 0424f7561..000000000 --- a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial003.py +++ /dev/null @@ -1,112 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select, text - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team", passive_deletes="all") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", ondelete="SET NULL" - ) - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - with engine.connect() as connection: - connection.execute(text("PRAGMA foreign_keys=ON")) # for SQLite only - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - -def delete_team(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - session.delete(team) - session.commit() - print("Deleted team:", team) - - -def select_deleted_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Black Lion") - result = session.exec(statement) - hero = result.first() - print("Black Lion has no team:", hero) - - statement = select(Hero).where(Hero.name == "Princess Sure-E") - result = session.exec(statement) - hero = result.first() - print("Princess Sure-E has no team:", hero) - - -def main(): - create_db_and_tables() - create_heroes() - delete_team() - select_deleted_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial004.py b/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial004.py deleted file mode 100644 index 00c5ac176..000000000 --- a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial004.py +++ /dev/null @@ -1,111 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select, text - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team", passive_deletes="all") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", ondelete="RESTRICT" - ) - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - with engine.connect() as connection: - connection.execute(text("PRAGMA foreign_keys=ON")) # for SQLite only - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - -def delete_team(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - session.delete(team) - session.commit() - print("Deleted team:", team) - - -def select_deleted_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Black Lion") - result = session.exec(statement) - hero = result.first() - print("Black Lion has no team:", hero) - - statement = select(Hero).where(Hero.name == "Princess Sure-E") - result = session.exec(statement) - hero = result.first() - print("Princess Sure-E has no team:", hero) - - -def main(): - create_db_and_tables() - create_heroes() - delete_team() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial005.py b/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial005.py deleted file mode 100644 index b46a7781b..000000000 --- a/docs_src/tutorial/relationship_attributes/cascade_delete_relationships/tutorial005.py +++ /dev/null @@ -1,124 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select, text - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team", passive_deletes="all") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field( - default=None, foreign_key="team.id", ondelete="RESTRICT" - ) - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - with engine.connect() as connection: - connection.execute(text("PRAGMA foreign_keys=ON")) # for SQLite only - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - -def remove_team_heroes(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - team.heroes.clear() - session.add(team) - session.commit() - session.refresh(team) - print("Team with removed heroes:", team) - - -def delete_team(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Wakaland") - team = session.exec(statement).one() - session.delete(team) - session.commit() - print("Deleted team:", team) - - -def select_deleted_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Black Lion") - result = session.exec(statement) - hero = result.first() - print("Black Lion has no team:", hero) - - statement = select(Hero).where(Hero.name == "Princess Sure-E") - result = session.exec(statement) - hero = result.first() - print("Princess Sure-E has no team:", hero) - - -def main(): - create_db_and_tables() - create_heroes() - remove_team_heroes() - delete_team() - select_deleted_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/create_and_update_relationships/tutorial001.py b/docs_src/tutorial/relationship_attributes/create_and_update_relationships/tutorial001.py deleted file mode 100644 index 73c68cf96..000000000 --- a/docs_src/tutorial/relationship_attributes/create_and_update_relationships/tutorial001.py +++ /dev/null @@ -1,102 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - hero_tarantula = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32) - hero_dr_weird = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36) - hero_cap = Hero( - name="Captain North America", secret_name="Esteban Rogelios", age=93 - ) - - team_preventers.heroes.append(hero_tarantula) - team_preventers.heroes.append(hero_dr_weird) - team_preventers.heroes.append(hero_cap) - session.add(team_preventers) - session.commit() - session.refresh(hero_tarantula) - session.refresh(hero_dr_weird) - session.refresh(hero_cap) - print("Preventers new hero:", hero_tarantula) - print("Preventers new hero:", hero_dr_weird) - print("Preventers new hero:", hero_cap) - - -def main(): - create_db_and_tables() - create_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/define_relationship_attributes/tutorial001.py b/docs_src/tutorial/relationship_attributes/define_relationship_attributes/tutorial001.py deleted file mode 100644 index af218b956..000000000 --- a/docs_src/tutorial/relationship_attributes/define_relationship_attributes/tutorial001.py +++ /dev/null @@ -1,70 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - - -def main(): - create_db_and_tables() - create_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/read_relationships/tutorial001.py b/docs_src/tutorial/relationship_attributes/read_relationships/tutorial001.py deleted file mode 100644 index b8bbe70a4..000000000 --- a/docs_src/tutorial/relationship_attributes/read_relationships/tutorial001.py +++ /dev/null @@ -1,117 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - hero_tarantula = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32) - hero_dr_weird = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36) - hero_cap = Hero( - name="Captain North America", secret_name="Esteban Rogelios", age=93 - ) - - team_preventers.heroes.append(hero_tarantula) - team_preventers.heroes.append(hero_dr_weird) - team_preventers.heroes.append(hero_cap) - session.add(team_preventers) - session.commit() - session.refresh(hero_tarantula) - session.refresh(hero_dr_weird) - session.refresh(hero_cap) - print("Preventers new hero:", hero_tarantula) - print("Preventers new hero:", hero_dr_weird) - print("Preventers new hero:", hero_cap) - - -def select_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Spider-Boy") - result = session.exec(statement) - hero_spider_boy = result.one() - - statement = select(Team).where(Team.id == hero_spider_boy.team_id) - result = session.exec(statement) - team = result.first() - print("Spider-Boy's team:", team) - - print("Spider-Boy's team again:", hero_spider_boy.team) - - -def main(): - create_db_and_tables() - create_heroes() - select_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/relationship_attributes/read_relationships/tutorial002.py b/docs_src/tutorial/relationship_attributes/read_relationships/tutorial002.py deleted file mode 100644 index 30fa84087..000000000 --- a/docs_src/tutorial/relationship_attributes/read_relationships/tutorial002.py +++ /dev/null @@ -1,127 +0,0 @@ -from typing import List, Optional - -from sqlmodel import Field, Relationship, Session, SQLModel, create_engine, select - - -class Team(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - headquarters: str - - heroes: List["Hero"] = Relationship(back_populates="team") - - -class Hero(SQLModel, table=True): - id: Optional[int] = Field(default=None, primary_key=True) - name: str = Field(index=True) - secret_name: str - age: Optional[int] = Field(default=None, index=True) - - team_id: Optional[int] = Field(default=None, foreign_key="team.id") - team: Optional[Team] = Relationship(back_populates="heroes") - - -sqlite_file_name = "database.db" -sqlite_url = f"sqlite:///{sqlite_file_name}" - -engine = create_engine(sqlite_url, echo=True) - - -def create_db_and_tables(): - SQLModel.metadata.create_all(engine) - - -def create_heroes(): - with Session(engine) as session: - team_preventers = Team(name="Preventers", headquarters="Sharp Tower") - team_z_force = Team(name="Z-Force", headquarters="Sister Margaret's Bar") - - hero_deadpond = Hero( - name="Deadpond", secret_name="Dive Wilson", team=team_z_force - ) - hero_rusty_man = Hero( - name="Rusty-Man", secret_name="Tommy Sharp", age=48, team=team_preventers - ) - hero_spider_boy = Hero(name="Spider-Boy", secret_name="Pedro Parqueador") - session.add(hero_deadpond) - session.add(hero_rusty_man) - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_deadpond) - session.refresh(hero_rusty_man) - session.refresh(hero_spider_boy) - - print("Created hero:", hero_deadpond) - print("Created hero:", hero_rusty_man) - print("Created hero:", hero_spider_boy) - - hero_spider_boy.team = team_preventers - session.add(hero_spider_boy) - session.commit() - session.refresh(hero_spider_boy) - print("Updated hero:", hero_spider_boy) - - hero_black_lion = Hero(name="Black Lion", secret_name="Trevor Challa", age=35) - hero_sure_e = Hero(name="Princess Sure-E", secret_name="Sure-E") - team_wakaland = Team( - name="Wakaland", - headquarters="Wakaland Capital City", - heroes=[hero_black_lion, hero_sure_e], - ) - session.add(team_wakaland) - session.commit() - session.refresh(team_wakaland) - print("Team Wakaland:", team_wakaland) - - hero_tarantula = Hero(name="Tarantula", secret_name="Natalia Roman-on", age=32) - hero_dr_weird = Hero(name="Dr. Weird", secret_name="Steve Weird", age=36) - hero_cap = Hero( - name="Captain North America", secret_name="Esteban Rogelios", age=93 - ) - - team_preventers.heroes.append(hero_tarantula) - team_preventers.heroes.append(hero_dr_weird) - team_preventers.heroes.append(hero_cap) - session.add(team_preventers) - session.commit() - session.refresh(hero_tarantula) - session.refresh(hero_dr_weird) - session.refresh(hero_cap) - print("Preventers new hero:", hero_tarantula) - print("Preventers new hero:", hero_dr_weird) - print("Preventers new hero:", hero_cap) - - -def select_heroes(): - with Session(engine) as session: - statement = select(Team).where(Team.name == "Preventers") - result = session.exec(statement) - team_preventers = result.one() - - print("Preventers heroes:", team_preventers.heroes) - - -def update_heroes(): - with Session(engine) as session: - statement = select(Hero).where(Hero.name == "Spider-Boy") - result = session.exec(statement) - hero_spider_boy = result.one() - - hero_spider_boy.team = None - session.add(hero_spider_boy) - session.commit() - - session.refresh(hero_spider_boy) - print("Spider-Boy without team:", hero_spider_boy) - - -def main(): - create_db_and_tables() - create_heroes() - select_heroes() - update_heroes() - - -if __name__ == "__main__": - main() diff --git a/docs_src/tutorial/select/tutorial001.py b/docs_src/tutorial/select/tutorial001_py39.py similarity index 100% rename from docs_src/tutorial/select/tutorial001.py rename to docs_src/tutorial/select/tutorial001_py39.py diff --git a/docs_src/tutorial/select/tutorial002.py b/docs_src/tutorial/select/tutorial002_py39.py similarity index 100% rename from docs_src/tutorial/select/tutorial002.py rename to docs_src/tutorial/select/tutorial002_py39.py diff --git a/docs_src/tutorial/select/tutorial003.py b/docs_src/tutorial/select/tutorial003_py39.py similarity index 100% rename from docs_src/tutorial/select/tutorial003.py rename to docs_src/tutorial/select/tutorial003_py39.py diff --git a/docs_src/tutorial/select/tutorial004.py b/docs_src/tutorial/select/tutorial004_py39.py similarity index 100% rename from docs_src/tutorial/select/tutorial004.py rename to docs_src/tutorial/select/tutorial004_py39.py diff --git a/docs_src/tutorial/update/tutorial001.py b/docs_src/tutorial/update/tutorial001_py39.py similarity index 100% rename from docs_src/tutorial/update/tutorial001.py rename to docs_src/tutorial/update/tutorial001_py39.py diff --git a/docs_src/tutorial/update/tutorial002.py b/docs_src/tutorial/update/tutorial002_py39.py similarity index 100% rename from docs_src/tutorial/update/tutorial002.py rename to docs_src/tutorial/update/tutorial002_py39.py diff --git a/docs_src/tutorial/update/tutorial003.py b/docs_src/tutorial/update/tutorial003_py39.py similarity index 100% rename from docs_src/tutorial/update/tutorial003.py rename to docs_src/tutorial/update/tutorial003_py39.py diff --git a/docs_src/tutorial/update/tutorial004.py b/docs_src/tutorial/update/tutorial004_py39.py similarity index 100% rename from docs_src/tutorial/update/tutorial004.py rename to docs_src/tutorial/update/tutorial004_py39.py diff --git a/docs_src/tutorial/where/tutorial001.py b/docs_src/tutorial/where/tutorial001_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial001.py rename to docs_src/tutorial/where/tutorial001_py39.py diff --git a/docs_src/tutorial/where/tutorial002.py b/docs_src/tutorial/where/tutorial002_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial002.py rename to docs_src/tutorial/where/tutorial002_py39.py diff --git a/docs_src/tutorial/where/tutorial003.py b/docs_src/tutorial/where/tutorial003_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial003.py rename to docs_src/tutorial/where/tutorial003_py39.py diff --git a/docs_src/tutorial/where/tutorial004.py b/docs_src/tutorial/where/tutorial004_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial004.py rename to docs_src/tutorial/where/tutorial004_py39.py diff --git a/docs_src/tutorial/where/tutorial005.py b/docs_src/tutorial/where/tutorial005_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial005.py rename to docs_src/tutorial/where/tutorial005_py39.py diff --git a/docs_src/tutorial/where/tutorial006.py b/docs_src/tutorial/where/tutorial006_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial006.py rename to docs_src/tutorial/where/tutorial006_py39.py diff --git a/docs_src/tutorial/where/tutorial007.py b/docs_src/tutorial/where/tutorial007_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial007.py rename to docs_src/tutorial/where/tutorial007_py39.py diff --git a/docs_src/tutorial/where/tutorial008.py b/docs_src/tutorial/where/tutorial008_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial008.py rename to docs_src/tutorial/where/tutorial008_py39.py diff --git a/docs_src/tutorial/where/tutorial009.py b/docs_src/tutorial/where/tutorial009_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial009.py rename to docs_src/tutorial/where/tutorial009_py39.py diff --git a/docs_src/tutorial/where/tutorial010.py b/docs_src/tutorial/where/tutorial010_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial010.py rename to docs_src/tutorial/where/tutorial010_py39.py diff --git a/docs_src/tutorial/where/tutorial011.py b/docs_src/tutorial/where/tutorial011_py39.py similarity index 100% rename from docs_src/tutorial/where/tutorial011.py rename to docs_src/tutorial/where/tutorial011_py39.py diff --git a/requirements-tests.txt b/requirements-tests.txt index 936791db5..378eaca66 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -2,15 +2,11 @@ -r requirements-docs-tests.txt pytest >=7.0.1,<9.0.0 coverage[toml] >=6.2,<8.0 -# Remove when support for Python 3.8 is dropped -mypy ==1.14.1; python_version < "3.9" -mypy ==1.19.1; python_version >= "3.9" +mypy ==1.19.1 ruff ==0.14.10 # For FastAPI tests fastapi >=0.103.2,<0.126.0 httpx ==0.28.1 dirty-equals ==0.9.0 jinja2 ==3.1.6 -# Remove when support for Python 3.8 is dropped -typing-extensions ==4.13.2; python_version < "3.9" -typing-extensions ==4.15.0; python_version >= "3.9" +typing-extensions ==4.15.0 diff --git a/tests/conftest.py b/tests/conftest.py index 98a4d2b7e..d8da629db 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -31,7 +31,7 @@ def clear_sqlmodel() -> Any: def cov_tmp_path(tmp_path: Path) -> Generator[Path, None, None]: yield tmp_path for coverage_path in tmp_path.glob(".coverage*"): - coverage_destiny_path = top_level_path / coverage_path.name + coverage_destiny_path = top_level_path / "coverage" / coverage_path.name shutil.copy(coverage_path, coverage_destiny_path) @@ -89,7 +89,6 @@ def print_mock_fixture() -> Generator[PrintMock, None, None]: needs_pydanticv2 = pytest.mark.skipif(not IS_PYDANTIC_V2, reason="requires Pydantic v2") needs_pydanticv1 = pytest.mark.skipif(IS_PYDANTIC_V2, reason="requires Pydantic v1") -needs_py39 = pytest.mark.skipif(sys.version_info < (3, 9), reason="requires python3.9+") needs_py310 = pytest.mark.skipif( sys.version_info < (3, 10), reason="requires python3.10+" ) diff --git a/tests/test_advanced/test_decimal/test_tutorial001.py b/tests/test_advanced/test_decimal/test_tutorial001.py index dad8f24c4..2e839e0e2 100644 --- a/tests/test_advanced/test_decimal/test_tutorial001.py +++ b/tests/test_advanced/test_decimal/test_tutorial001.py @@ -11,7 +11,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_advanced/test_uuid/test_tutorial001.py b/tests/test_advanced/test_uuid/test_tutorial001.py index ab4f3387d..e453ef00e 100644 --- a/tests/test_advanced/test_uuid/test_tutorial001.py +++ b/tests/test_advanced/test_uuid/test_tutorial001.py @@ -11,7 +11,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_advanced/test_uuid/test_tutorial002.py b/tests/test_advanced/test_uuid/test_tutorial002.py index b1ff5ba3f..e171c1e0e 100644 --- a/tests/test_advanced/test_uuid/test_tutorial002.py +++ b/tests/test_advanced/test_uuid/test_tutorial002.py @@ -11,7 +11,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_select_gen.py b/tests/test_select_gen.py index 664cebf2a..94ed340e9 100644 --- a/tests/test_select_gen.py +++ b/tests/test_select_gen.py @@ -3,12 +3,9 @@ import subprocess import sys from pathlib import Path -from .conftest import needs_py39 - root_path = Path(__file__).parent.parent -@needs_py39 def test_select_gen() -> None: env = os.environ.copy() env["CHECK_JINJA"] = "1" diff --git a/tests/test_tutorial/test_automatic_id_none_refresh/test_tutorial001_tutorial002.py b/tests/test_tutorial/test_automatic_id_none_refresh/test_tutorial001_tutorial002.py index 7233e40be..b2c452f90 100644 --- a/tests/test_tutorial/test_automatic_id_none_refresh/test_tutorial001_tutorial002.py +++ b/tests/test_tutorial/test_automatic_id_none_refresh/test_tutorial001_tutorial002.py @@ -138,8 +138,8 @@ def check_calls(calls: List[List[Union[str, Dict[str, Any]]]]) -> None: @pytest.fixture( name="module", params=[ - "tutorial001", - "tutorial002", + "tutorial001_py39", + "tutorial002_py39", pytest.param("tutorial001_py310", marks=needs_py310), pytest.param("tutorial002_py310", marks=needs_py310), ], diff --git a/tests/test_tutorial/test_code_structure/test_tutorial001.py b/tests/test_tutorial/test_code_structure/test_tutorial001.py index 99ae5c00f..aa832f622 100644 --- a/tests/test_tutorial/test_code_structure/test_tutorial001.py +++ b/tests/test_tutorial/test_code_structure/test_tutorial001.py @@ -5,7 +5,7 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from tests.conftest import PrintMock, needs_py39, needs_py310 +from tests.conftest import PrintMock, needs_py310 expected_calls = [ [ @@ -34,8 +34,7 @@ class Modules: @pytest.fixture( name="modules", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_code_structure/test_tutorial002.py b/tests/test_tutorial/test_code_structure/test_tutorial002.py index f1d4043e8..990d3ecaa 100644 --- a/tests/test_tutorial/test_code_structure/test_tutorial002.py +++ b/tests/test_tutorial/test_code_structure/test_tutorial002.py @@ -5,7 +5,7 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ...conftest import PrintMock, needs_py39, needs_py310 +from ...conftest import PrintMock, needs_py310 expected_calls = [ [ @@ -34,8 +34,7 @@ class Modules: @pytest.fixture( name="modules", params=[ - "tutorial002", - pytest.param("tutorial002_py39", marks=needs_py39), + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_connect/test_create_connected_tables/test_tutorial001.py b/tests/test_tutorial/test_connect/test_create_connected_tables/test_tutorial001.py index 49d4acfa0..66e57debe 100644 --- a/tests/test_tutorial/test_connect/test_create_connected_tables/test_tutorial001.py +++ b/tests/test_tutorial/test_connect/test_create_connected_tables/test_tutorial001.py @@ -12,7 +12,7 @@ from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", + "tutorial001_py39", pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_connect/test_delete/test_tutorial001.py b/tests/test_tutorial/test_connect/test_delete/test_tutorial001.py index cc25dd42e..7e20767f5 100644 --- a/tests/test_tutorial/test_connect/test_delete/test_tutorial001.py +++ b/tests/test_tutorial/test_connect/test_delete/test_tutorial001.py @@ -63,7 +63,7 @@ expected_calls = [ @pytest.fixture( name="module", params=[ - "tutorial001", + "tutorial001_py39", pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_connect/test_insert/test_tutorial001.py b/tests/test_tutorial/test_connect/test_insert/test_tutorial001.py index 6c4ec3ab1..c7363a073 100644 --- a/tests/test_tutorial/test_connect/test_insert/test_tutorial001.py +++ b/tests/test_tutorial/test_connect/test_insert/test_tutorial001.py @@ -43,7 +43,7 @@ expected_calls = [ @pytest.fixture( name="module", params=[ - "tutorial001", + "tutorial001_py39", pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_connect/test_select/test_tutorial001_tutorial002.py b/tests/test_tutorial/test_connect/test_select/test_tutorial001_tutorial002.py index 6553bc1ae..4b141f11d 100644 --- a/tests/test_tutorial/test_connect/test_select/test_tutorial001_tutorial002.py +++ b/tests/test_tutorial/test_connect/test_select/test_tutorial001_tutorial002.py @@ -77,7 +77,7 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType: @pytest.mark.parametrize( "module", [ - "tutorial001", + "tutorial001_py39", pytest.param("tutorial001_py310", marks=needs_py310), ], indirect=True, @@ -90,7 +90,7 @@ def test_tutorial001(print_mock: PrintMock, module: ModuleType): @pytest.mark.parametrize( "module", [ - "tutorial002", + "tutorial002_py39", pytest.param("tutorial002_py310", marks=needs_py310), ], indirect=True, diff --git a/tests/test_tutorial/test_connect/test_select/test_tutorial003.py b/tests/test_tutorial/test_connect/test_select/test_tutorial003.py index 6036b672a..3ded56065 100644 --- a/tests/test_tutorial/test_connect/test_select/test_tutorial003.py +++ b/tests/test_tutorial/test_connect/test_select/test_tutorial003.py @@ -79,7 +79,7 @@ expected_calls = [ @pytest.fixture( name="module", params=[ - "tutorial003", + "tutorial003_py39", pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_connect/test_select/test_tutorial004.py b/tests/test_tutorial/test_connect/test_select/test_tutorial004.py index c9fa695ed..7e8240bb0 100644 --- a/tests/test_tutorial/test_connect/test_select/test_tutorial004.py +++ b/tests/test_tutorial/test_connect/test_select/test_tutorial004.py @@ -53,7 +53,7 @@ expected_calls = [ @pytest.fixture( name="module", params=[ - "tutorial004", + "tutorial004_py39", pytest.param("tutorial004_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_connect/test_select/test_tutorial005.py b/tests/test_tutorial/test_connect/test_select/test_tutorial005.py index 12d98b7e6..004229a29 100644 --- a/tests/test_tutorial/test_connect/test_select/test_tutorial005.py +++ b/tests/test_tutorial/test_connect/test_select/test_tutorial005.py @@ -55,7 +55,7 @@ expected_calls = [ @pytest.fixture( name="module", params=[ - "tutorial005", + "tutorial005_py39", pytest.param("tutorial005_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_connect/test_update/test_tutorial001.py b/tests/test_tutorial/test_connect/test_update/test_tutorial001.py index aa94c9121..7120dce7e 100644 --- a/tests/test_tutorial/test_connect/test_update/test_tutorial001.py +++ b/tests/test_tutorial/test_connect/test_update/test_tutorial001.py @@ -53,7 +53,7 @@ expected_calls = [ @pytest.fixture( name="module", params=[ - "tutorial001", + "tutorial001_py39", pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_create_db_and_table/test_tutorial001.py b/tests/test_tutorial/test_create_db_and_table/test_tutorial001.py index 4aeeb64b6..3e054bf3e 100644 --- a/tests/test_tutorial/test_create_db_and_table/test_tutorial001.py +++ b/tests/test_tutorial/test_create_db_and_table/test_tutorial001.py @@ -8,7 +8,7 @@ from ...conftest import coverage_run, needs_py310 @pytest.mark.parametrize( "module_name", [ - "tutorial001", + "tutorial001_py39", pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_create_db_and_table/test_tutorial002.py b/tests/test_tutorial/test_create_db_and_table/test_tutorial002.py index 0f1ad85fe..f92bfee71 100644 --- a/tests/test_tutorial/test_create_db_and_table/test_tutorial002.py +++ b/tests/test_tutorial/test_create_db_and_table/test_tutorial002.py @@ -12,7 +12,7 @@ from ...conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial002", + "tutorial002_py39", pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_create_db_and_table/test_tutorial003.py b/tests/test_tutorial/test_create_db_and_table/test_tutorial003.py index 446feae71..e11e0a047 100644 --- a/tests/test_tutorial/test_create_db_and_table/test_tutorial003.py +++ b/tests/test_tutorial/test_create_db_and_table/test_tutorial003.py @@ -12,7 +12,7 @@ from ...conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial003", + "tutorial003_py39", pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_delete/test_tutorial001_tutorial002.py b/tests/test_tutorial/test_delete/test_tutorial001_tutorial002.py index 3d755ae02..5e6c354b3 100644 --- a/tests/test_tutorial/test_delete/test_tutorial001_tutorial002.py +++ b/tests/test_tutorial/test_delete/test_tutorial001_tutorial002.py @@ -71,7 +71,7 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType: @pytest.mark.parametrize( "module", [ - "tutorial001", + "tutorial001_py39", pytest.param("tutorial001_py310", marks=needs_py310), ], indirect=True, @@ -84,7 +84,7 @@ def test_tutorial001(print_mock: PrintMock, module: ModuleType): @pytest.mark.parametrize( "module", [ - "tutorial002", + "tutorial002_py39", pytest.param("tutorial002_py310", marks=needs_py310), ], indirect=True, diff --git a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests001.py b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests001.py index 95be986fc..71fc72318 100644 --- a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests001.py +++ b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests001.py @@ -5,7 +5,7 @@ from types import ModuleType import pytest -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @dataclass @@ -17,8 +17,7 @@ class Modules: @pytest.fixture( name="modules_path", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests002.py b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests002.py index 1f360c6f1..73bf080ec 100644 --- a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests002.py +++ b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests002.py @@ -5,7 +5,7 @@ from types import ModuleType import pytest -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @dataclass @@ -17,8 +17,7 @@ class Modules: @pytest.fixture( name="modules_path", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) @@ -35,7 +34,7 @@ def load_modules(clear_sqlmodel, modules_path: str) -> Modules: app_mod = sys.modules[app_mod_path] importlib.reload(app_mod) else: - app_mod = importlib.import_module(app_mod_path) + app_mod = importlib.import_module(app_mod_path) # pragma: no cover test_mod = importlib.import_module(f"{modules_path}.test_main_002") return Modules(app=app_mod, test=test_mod) diff --git a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests003.py b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests003.py index 4911173b6..41c4d5730 100644 --- a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests003.py +++ b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests003.py @@ -5,7 +5,7 @@ from types import ModuleType import pytest -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @dataclass @@ -17,8 +17,7 @@ class Modules: @pytest.fixture( name="modules_path", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) @@ -35,7 +34,7 @@ def load_modules(clear_sqlmodel, modules_path: str) -> Modules: app_mod = sys.modules[app_mod_path] importlib.reload(app_mod) else: - app_mod = importlib.import_module(app_mod_path) + app_mod = importlib.import_module(app_mod_path) # pragma: no cover test_mod = importlib.import_module(f"{modules_path}.test_main_003") return Modules(app=app_mod, test=test_mod) diff --git a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests004.py b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests004.py index b3ca441d2..ba3a61ad1 100644 --- a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests004.py +++ b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests004.py @@ -5,7 +5,7 @@ from types import ModuleType import pytest -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @dataclass @@ -17,8 +17,7 @@ class Modules: @pytest.fixture( name="modules_path", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) @@ -35,7 +34,7 @@ def load_modules(clear_sqlmodel, modules_path: str) -> Modules: app_mod = sys.modules[app_mod_path] importlib.reload(app_mod) else: - app_mod = importlib.import_module(app_mod_path) + app_mod = importlib.import_module(app_mod_path) # pragma: no cover test_mod = importlib.import_module(f"{modules_path}.test_main_004") return Modules(app=app_mod, test=test_mod) diff --git a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests005.py b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests005.py index cc550c400..5d704ffb5 100644 --- a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests005.py +++ b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests005.py @@ -3,9 +3,11 @@ import importlib import pytest from sqlmodel import Session -from docs_src.tutorial.fastapi.app_testing.tutorial001 import main as app_mod -from docs_src.tutorial.fastapi.app_testing.tutorial001 import test_main_005 as test_mod -from docs_src.tutorial.fastapi.app_testing.tutorial001.test_main_005 import ( +from docs_src.tutorial.fastapi.app_testing.tutorial001_py39 import main as app_mod +from docs_src.tutorial.fastapi.app_testing.tutorial001_py39 import ( + test_main_005 as test_mod, +) +from docs_src.tutorial.fastapi.app_testing.tutorial001_py39.test_main_005 import ( session_fixture, ) diff --git a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests006.py b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests006.py index 67c9ac6ad..1d474a7ec 100644 --- a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests006.py +++ b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests006.py @@ -4,9 +4,11 @@ import pytest from fastapi.testclient import TestClient from sqlmodel import Session -from docs_src.tutorial.fastapi.app_testing.tutorial001 import main as app_mod -from docs_src.tutorial.fastapi.app_testing.tutorial001 import test_main_006 as test_mod -from docs_src.tutorial.fastapi.app_testing.tutorial001.test_main_006 import ( +from docs_src.tutorial.fastapi.app_testing.tutorial001_py39 import main as app_mod +from docs_src.tutorial.fastapi.app_testing.tutorial001_py39 import ( + test_main_006 as test_mod, +) +from docs_src.tutorial.fastapi.app_testing.tutorial001_py39.test_main_006 import ( client_fixture, session_fixture, ) diff --git a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests_main.py b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests_main.py index 28959f79d..c6d942ea3 100644 --- a/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests_main.py +++ b/tests/test_tutorial/test_fastapi/test_app_testing/test_tutorial001_tests_main.py @@ -5,14 +5,13 @@ from types import ModuleType import pytest -from ....conftest import needs_py39, needs_py310 +from ....conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_delete/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_delete/test_tutorial001.py index 1480a06f5..ffbf7587f 100644 --- a/tests/test_tutorial/test_fastapi/test_delete/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_delete/test_tutorial001.py @@ -7,14 +7,13 @@ from fastapi.testclient import TestClient from sqlmodel import create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_limit_and_offset/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_limit_and_offset/test_tutorial001.py index dc3db8b5b..cbc722c5c 100644 --- a/tests/test_tutorial/test_fastapi/test_limit_and_offset/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_limit_and_offset/test_tutorial001.py @@ -7,14 +7,13 @@ from fastapi.testclient import TestClient from sqlmodel import create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py index 27629c891..d70dce32e 100644 --- a/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial001.py @@ -9,14 +9,13 @@ from sqlalchemy.engine.reflection import Inspector from sqlmodel import create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py b/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py index c840bde25..8d7c8064e 100644 --- a/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py +++ b/tests/test_tutorial/test_fastapi/test_multiple_models/test_tutorial002.py @@ -9,14 +9,13 @@ from sqlalchemy.engine.reflection import Inspector from sqlmodel import create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial002", - pytest.param("tutorial002_py39", marks=needs_py39), + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_read_one/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_read_one/test_tutorial001.py index affea513d..7ebbecd8d 100644 --- a/tests/test_tutorial/test_fastapi/test_read_one/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_read_one/test_tutorial001.py @@ -7,14 +7,13 @@ from fastapi.testclient import TestClient from sqlmodel import create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_relationships/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_relationships/test_tutorial001.py index 1d0446ed4..cf24466c1 100644 --- a/tests/test_tutorial/test_fastapi/test_relationships/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_relationships/test_tutorial001.py @@ -7,14 +7,13 @@ from fastapi.testclient import TestClient from sqlmodel import create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_response_model/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_response_model/test_tutorial001.py index 186a12031..1ad004e93 100644 --- a/tests/test_tutorial/test_fastapi/test_response_model/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_response_model/test_tutorial001.py @@ -7,14 +7,13 @@ from fastapi.testclient import TestClient from sqlmodel import create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_session_with_dependency/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_session_with_dependency/test_tutorial001.py index 184fb219a..6e441cccb 100644 --- a/tests/test_tutorial/test_fastapi/test_session_with_dependency/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_session_with_dependency/test_tutorial001.py @@ -7,14 +7,13 @@ from fastapi.testclient import TestClient from sqlmodel import create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_simple_hero_api/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_simple_hero_api/test_tutorial001.py index dba7bc387..b803cee28 100644 --- a/tests/test_tutorial/test_fastapi/test_simple_hero_api/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_simple_hero_api/test_tutorial001.py @@ -13,7 +13,7 @@ from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_teams/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_teams/test_tutorial001.py index 2e7d66a03..3b028b7d9 100644 --- a/tests/test_tutorial/test_fastapi/test_teams/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_teams/test_tutorial001.py @@ -7,14 +7,13 @@ from fastapi.testclient import TestClient from sqlmodel import create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_update/test_tutorial001.py b/tests/test_tutorial/test_fastapi/test_update/test_tutorial001.py index b6ee27611..9bc54fbcf 100644 --- a/tests/test_tutorial/test_fastapi/test_update/test_tutorial001.py +++ b/tests/test_tutorial/test_fastapi/test_update/test_tutorial001.py @@ -7,14 +7,13 @@ from fastapi.testclient import TestClient from sqlmodel import create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_fastapi/test_update/test_tutorial002.py b/tests/test_tutorial/test_fastapi/test_update/test_tutorial002.py index a9312651b..ede67fe4e 100644 --- a/tests/test_tutorial/test_fastapi/test_update/test_tutorial002.py +++ b/tests/test_tutorial/test_fastapi/test_update/test_tutorial002.py @@ -7,14 +7,13 @@ from fastapi.testclient import TestClient from sqlmodel import Session, create_engine from sqlmodel.pool import StaticPool -from tests.conftest import needs_py39, needs_py310 +from tests.conftest import needs_py310 @pytest.fixture( name="module", params=[ - "tutorial002", - pytest.param("tutorial002_py39", marks=needs_py39), + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_indexes/test_tutorial001.py b/tests/test_tutorial/test_indexes/test_tutorial001.py index b71f7ebd8..8f031a8a3 100644 --- a/tests/test_tutorial/test_indexes/test_tutorial001.py +++ b/tests/test_tutorial/test_indexes/test_tutorial001.py @@ -12,7 +12,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_indexes/test_tutorial002.py b/tests/test_tutorial/test_indexes/test_tutorial002.py index 0aa88ea5d..29b0987a4 100644 --- a/tests/test_tutorial/test_indexes/test_tutorial002.py +++ b/tests/test_tutorial/test_indexes/test_tutorial002.py @@ -12,7 +12,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_insert/test_tutorial001.py b/tests/test_tutorial/test_insert/test_tutorial001.py index 1673a7075..6e20feeb1 100644 --- a/tests/test_tutorial/test_insert/test_tutorial001.py +++ b/tests/test_tutorial/test_insert/test_tutorial001.py @@ -10,7 +10,7 @@ from ...conftest import needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_insert/test_tutorial002.py b/tests/test_tutorial/test_insert/test_tutorial002.py index 0cee7ef3b..b70ac6373 100644 --- a/tests/test_tutorial/test_insert/test_tutorial002.py +++ b/tests/test_tutorial/test_insert/test_tutorial002.py @@ -10,7 +10,7 @@ from ...conftest import needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_insert/test_tutorial003.py b/tests/test_tutorial/test_insert/test_tutorial003.py index 7f8058587..902f5519d 100644 --- a/tests/test_tutorial/test_insert/test_tutorial003.py +++ b/tests/test_tutorial/test_insert/test_tutorial003.py @@ -10,7 +10,7 @@ from ...conftest import needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial003", + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_limit_and_offset/test_tutorial001.py b/tests/test_tutorial/test_limit_and_offset/test_tutorial001.py index d33713cde..b1b581e38 100644 --- a/tests/test_tutorial/test_limit_and_offset/test_tutorial001.py +++ b/tests/test_tutorial/test_limit_and_offset/test_tutorial001.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_limit_and_offset/test_tutorial002.py b/tests/test_tutorial/test_limit_and_offset/test_tutorial002.py index c73f701cd..896f2bfce 100644 --- a/tests/test_tutorial/test_limit_and_offset/test_tutorial002.py +++ b/tests/test_tutorial/test_limit_and_offset/test_tutorial002.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_limit_and_offset/test_tutorial003.py b/tests/test_tutorial/test_limit_and_offset/test_tutorial003.py index a33cf49f0..8e9e0b730 100644 --- a/tests/test_tutorial/test_limit_and_offset/test_tutorial003.py +++ b/tests/test_tutorial/test_limit_and_offset/test_tutorial003.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial003", + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_limit_and_offset/test_tutorial004.py b/tests/test_tutorial/test_limit_and_offset/test_tutorial004.py index 15322c408..228acd6aa 100644 --- a/tests/test_tutorial/test_limit_and_offset/test_tutorial004.py +++ b/tests/test_tutorial/test_limit_and_offset/test_tutorial004.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial004", + pytest.param("tutorial004_py39"), pytest.param("tutorial004_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_many_to_many/test_tutorial001.py b/tests/test_tutorial/test_many_to_many/test_tutorial001.py index b84626d9c..427fe4189 100644 --- a/tests/test_tutorial/test_many_to_many/test_tutorial001.py +++ b/tests/test_tutorial/test_many_to_many/test_tutorial001.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ...conftest import PrintMock, needs_py39, needs_py310 +from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_many_to_many/test_tutorial002.py b/tests/test_tutorial/test_many_to_many/test_tutorial002.py index b5562f416..7ac120d5a 100644 --- a/tests/test_tutorial/test_many_to_many/test_tutorial002.py +++ b/tests/test_tutorial/test_many_to_many/test_tutorial002.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ...conftest import PrintMock, needs_py39, needs_py310 +from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", - pytest.param("tutorial002_py39", marks=needs_py39), + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_many_to_many/test_tutorial003.py b/tests/test_tutorial/test_many_to_many/test_tutorial003.py index ad1168e3b..6c14445b0 100644 --- a/tests/test_tutorial/test_many_to_many/test_tutorial003.py +++ b/tests/test_tutorial/test_many_to_many/test_tutorial003.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ...conftest import PrintMock, needs_py39, needs_py310 +from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial003", - pytest.param("tutorial003_py39", marks=needs_py39), + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_one/test_tutorial001.py b/tests/test_tutorial/test_one/test_tutorial001.py index 2f6f1c9e8..a4dd986ba 100644 --- a/tests/test_tutorial/test_one/test_tutorial001.py +++ b/tests/test_tutorial/test_one/test_tutorial001.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_one/test_tutorial002.py b/tests/test_tutorial/test_one/test_tutorial002.py index 267ead893..96dda11d2 100644 --- a/tests/test_tutorial/test_one/test_tutorial002.py +++ b/tests/test_tutorial/test_one/test_tutorial002.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_one/test_tutorial003.py b/tests/test_tutorial/test_one/test_tutorial003.py index de2e529ae..5de20da91 100644 --- a/tests/test_tutorial/test_one/test_tutorial003.py +++ b/tests/test_tutorial/test_one/test_tutorial003.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial003", + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_one/test_tutorial004.py b/tests/test_tutorial/test_one/test_tutorial004.py index 9df91fbb4..fce827718 100644 --- a/tests/test_tutorial/test_one/test_tutorial004.py +++ b/tests/test_tutorial/test_one/test_tutorial004.py @@ -11,7 +11,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial004", + pytest.param("tutorial004_py39"), pytest.param("tutorial004_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_one/test_tutorial005.py b/tests/test_tutorial/test_one/test_tutorial005.py index fa569020a..a4f791406 100644 --- a/tests/test_tutorial/test_one/test_tutorial005.py +++ b/tests/test_tutorial/test_one/test_tutorial005.py @@ -11,7 +11,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial005", + pytest.param("tutorial005_py39"), pytest.param("tutorial005_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_one/test_tutorial006.py b/tests/test_tutorial/test_one/test_tutorial006.py index 1c6c663dc..4ae19a5ee 100644 --- a/tests/test_tutorial/test_one/test_tutorial006.py +++ b/tests/test_tutorial/test_one/test_tutorial006.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial006", + pytest.param("tutorial006_py39"), pytest.param("tutorial006_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_one/test_tutorial007.py b/tests/test_tutorial/test_one/test_tutorial007.py index ca4a5310a..edf674fef 100644 --- a/tests/test_tutorial/test_one/test_tutorial007.py +++ b/tests/test_tutorial/test_one/test_tutorial007.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial007", + pytest.param("tutorial007_py39"), pytest.param("tutorial007_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_one/test_tutorial008.py b/tests/test_tutorial/test_one/test_tutorial008.py index da451fbaa..5a8e03a2d 100644 --- a/tests/test_tutorial/test_one/test_tutorial008.py +++ b/tests/test_tutorial/test_one/test_tutorial008.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial008", + pytest.param("tutorial008_py39"), pytest.param("tutorial008_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_one/test_tutorial009.py b/tests/test_tutorial/test_one/test_tutorial009.py index 0cf3a6267..bfd1d3a2c 100644 --- a/tests/test_tutorial/test_one/test_tutorial009.py +++ b/tests/test_tutorial/test_one/test_tutorial009.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial009", + pytest.param("tutorial009_py39"), pytest.param("tutorial009_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial001.py b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial001.py index 698a7af2c..208cfb7ca 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial001.py +++ b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial001.py @@ -5,14 +5,13 @@ import pytest from sqlalchemy.exc import SAWarning from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial002.py b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial002.py index 8ce54be46..65a849f27 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial002.py +++ b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial002.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", - pytest.param("tutorial002_py39", marks=needs_py39), + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial003.py b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial003.py index d30c71c3c..a23800db9 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial003.py +++ b/tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial003.py @@ -6,14 +6,13 @@ from sqlalchemy import inspect from sqlalchemy.engine.reflection import Inspector from sqlmodel import create_engine -from ....conftest import needs_py39, needs_py310 +from ....conftest import needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial003", - pytest.param("tutorial003_py39", marks=needs_py39), + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_create_and_update_relationships/test_tutorial001.py b/tests/test_tutorial/test_relationship_attributes/test_create_and_update_relationships/test_tutorial001.py index 0c6a22917..d73be8f3c 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_create_and_update_relationships/test_tutorial001.py +++ b/tests/test_tutorial/test_relationship_attributes/test_create_and_update_relationships/test_tutorial001.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_define_relationship_attributes/test_tutorial001.py b/tests/test_tutorial/test_relationship_attributes/test_define_relationship_attributes/test_tutorial001.py index 96cf8bcc4..516f3e384 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_define_relationship_attributes/test_tutorial001.py +++ b/tests/test_tutorial/test_relationship_attributes/test_define_relationship_attributes/test_tutorial001.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial001.py b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial001.py index 5e43f80c4..fddaf3d9b 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial001.py +++ b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial001.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial002.py b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial002.py index cb3907afd..5614c2fec 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial002.py +++ b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial002.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", - pytest.param("tutorial002_py39", marks=needs_py39), + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial003.py b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial003.py index e063630f9..095062d7d 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial003.py +++ b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial003.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial003", - pytest.param("tutorial003_py39", marks=needs_py39), + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial004.py b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial004.py index 8b6c101fb..fb045d45a 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial004.py +++ b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial004.py @@ -5,14 +5,13 @@ import pytest from sqlalchemy.exc import IntegrityError from sqlmodel import Session, create_engine, select -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial004", - pytest.param("tutorial004_py39", marks=needs_py39), + pytest.param("tutorial004_py39"), pytest.param("tutorial004_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial005.py b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial005.py index 273007770..d2170f225 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial005.py +++ b/tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial005.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial005", - pytest.param("tutorial005_py39", marks=needs_py39), + pytest.param("tutorial005_py39"), pytest.param("tutorial005_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial001.py b/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial001.py index 1b2caaa9c..651f44a03 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial001.py +++ b/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial001.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", - pytest.param("tutorial001_py39", marks=needs_py39), + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial002.py b/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial002.py index 68ee2cc1d..306f3f174 100644 --- a/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial002.py +++ b/tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial002.py @@ -4,14 +4,13 @@ from types import ModuleType import pytest from sqlmodel import create_engine -from ....conftest import PrintMock, needs_py39, needs_py310 +from ....conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", - pytest.param("tutorial002_py39", marks=needs_py39), + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_select/test_tutorial001_tutorial002.py b/tests/test_tutorial/test_select/test_tutorial001_tutorial002.py index a3f5e90d4..3dc5c186c 100644 --- a/tests/test_tutorial/test_select/test_tutorial001_tutorial002.py +++ b/tests/test_tutorial/test_select/test_tutorial001_tutorial002.py @@ -40,7 +40,7 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType: @pytest.mark.parametrize( "module", [ - "tutorial001", + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], indirect=True, @@ -53,7 +53,7 @@ def test_tutorial_001(print_mock: PrintMock, module: ModuleType): @pytest.mark.parametrize( "module", [ - "tutorial002", + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], indirect=True, diff --git a/tests/test_tutorial/test_select/test_tutorial003_tutorial004.py b/tests/test_tutorial/test_select/test_tutorial003_tutorial004.py index 967ecdbd5..e64d5f8b7 100644 --- a/tests/test_tutorial/test_select/test_tutorial003_tutorial004.py +++ b/tests/test_tutorial/test_select/test_tutorial003_tutorial004.py @@ -42,7 +42,7 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType: @pytest.mark.parametrize( "module", [ - "tutorial003", + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], indirect=True, @@ -55,7 +55,7 @@ def test_tutorial_003(print_mock: PrintMock, module: ModuleType): @pytest.mark.parametrize( "module", [ - "tutorial004", + pytest.param("tutorial004_py39"), pytest.param("tutorial004_py310", marks=needs_py310), ], indirect=True, diff --git a/tests/test_tutorial/test_update/test_tutorial001_tutorial002.py b/tests/test_tutorial/test_update/test_tutorial001_tutorial002.py index ef12a8d95..6f4b05ee1 100644 --- a/tests/test_tutorial/test_update/test_tutorial001_tutorial002.py +++ b/tests/test_tutorial/test_update/test_tutorial001_tutorial002.py @@ -39,7 +39,7 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType: @pytest.mark.parametrize( "module", [ - "tutorial001", + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], indirect=True, @@ -52,7 +52,7 @@ def test_tutorial001(print_mock: PrintMock, module: ModuleType): @pytest.mark.parametrize( "module", [ - "tutorial002", + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], indirect=True, diff --git a/tests/test_tutorial/test_update/test_tutorial003_tutorial004.py b/tests/test_tutorial/test_update/test_tutorial003_tutorial004.py index 76788c62c..944b2ebf0 100644 --- a/tests/test_tutorial/test_update/test_tutorial003_tutorial004.py +++ b/tests/test_tutorial/test_update/test_tutorial003_tutorial004.py @@ -52,7 +52,7 @@ def get_module(request: pytest.FixtureRequest) -> ModuleType: @pytest.mark.parametrize( "module", [ - "tutorial003", + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], indirect=True, @@ -65,7 +65,7 @@ def test_tutorial003(print_mock: PrintMock, module: ModuleType): @pytest.mark.parametrize( "module", [ - "tutorial004", + pytest.param("tutorial004_py39"), pytest.param("tutorial004_py310", marks=needs_py310), ], indirect=True, diff --git a/tests/test_tutorial/test_where/test_tutorial001.py b/tests/test_tutorial/test_where/test_tutorial001.py index 1a557deef..a6b869d81 100644 --- a/tests/test_tutorial/test_where/test_tutorial001.py +++ b/tests/test_tutorial/test_where/test_tutorial001.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial001", + pytest.param("tutorial001_py39"), pytest.param("tutorial001_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_where/test_tutorial002.py b/tests/test_tutorial/test_where/test_tutorial002.py index 1c96f7612..7c6812fb2 100644 --- a/tests/test_tutorial/test_where/test_tutorial002.py +++ b/tests/test_tutorial/test_where/test_tutorial002.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial002", + pytest.param("tutorial002_py39"), pytest.param("tutorial002_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_where/test_tutorial003.py b/tests/test_tutorial/test_where/test_tutorial003.py index 6e90d22fc..304310a77 100644 --- a/tests/test_tutorial/test_where/test_tutorial003.py +++ b/tests/test_tutorial/test_where/test_tutorial003.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial003", + pytest.param("tutorial003_py39"), pytest.param("tutorial003_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_where/test_tutorial004.py b/tests/test_tutorial/test_where/test_tutorial004.py index b7a1212b7..bace062f6 100644 --- a/tests/test_tutorial/test_where/test_tutorial004.py +++ b/tests/test_tutorial/test_where/test_tutorial004.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial004", + pytest.param("tutorial004_py39"), pytest.param("tutorial004_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_where/test_tutorial005.py b/tests/test_tutorial/test_where/test_tutorial005.py index 9adbec74a..39f7b1b2b 100644 --- a/tests/test_tutorial/test_where/test_tutorial005.py +++ b/tests/test_tutorial/test_where/test_tutorial005.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial005", + pytest.param("tutorial005_py39"), pytest.param("tutorial005_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_where/test_tutorial006.py b/tests/test_tutorial/test_where/test_tutorial006.py index e5d586a39..9830142ad 100644 --- a/tests/test_tutorial/test_where/test_tutorial006.py +++ b/tests/test_tutorial/test_where/test_tutorial006.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial006", + pytest.param("tutorial006_py39"), pytest.param("tutorial006_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_where/test_tutorial007.py b/tests/test_tutorial/test_where/test_tutorial007.py index 9a36279d3..c2650193d 100644 --- a/tests/test_tutorial/test_where/test_tutorial007.py +++ b/tests/test_tutorial/test_where/test_tutorial007.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial007", + pytest.param("tutorial007_py39"), pytest.param("tutorial007_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_where/test_tutorial008.py b/tests/test_tutorial/test_where/test_tutorial008.py index a21e2ecbe..ac5ccf055 100644 --- a/tests/test_tutorial/test_where/test_tutorial008.py +++ b/tests/test_tutorial/test_where/test_tutorial008.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial008", + pytest.param("tutorial008_py39"), pytest.param("tutorial008_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_where/test_tutorial009.py b/tests/test_tutorial/test_where/test_tutorial009.py index 8088045b0..22b359768 100644 --- a/tests/test_tutorial/test_where/test_tutorial009.py +++ b/tests/test_tutorial/test_where/test_tutorial009.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial009", + pytest.param("tutorial009_py39"), pytest.param("tutorial009_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_where/test_tutorial010.py b/tests/test_tutorial/test_where/test_tutorial010.py index ea235ef70..8740de1a7 100644 --- a/tests/test_tutorial/test_where/test_tutorial010.py +++ b/tests/test_tutorial/test_where/test_tutorial010.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial010", + pytest.param("tutorial010_py39"), pytest.param("tutorial010_py310", marks=needs_py310), ], ) diff --git a/tests/test_tutorial/test_where/test_tutorial011.py b/tests/test_tutorial/test_where/test_tutorial011.py index ba5355061..8131e2adc 100644 --- a/tests/test_tutorial/test_where/test_tutorial011.py +++ b/tests/test_tutorial/test_where/test_tutorial011.py @@ -10,7 +10,7 @@ from ...conftest import PrintMock, needs_py310 @pytest.fixture( name="mod", params=[ - "tutorial011", + pytest.param("tutorial011_py39"), pytest.param("tutorial011_py310", marks=needs_py310), ], )