Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@ on:
push:

jobs:

Tests:
strategy:
matrix:
tox_env: [default, sqlmodel]
tox_env: [fastapi-pre121, fastapi-post121, sqlmodel]
runs-on: ubuntu-latest
steps:
- name: 📥 checkout
uses: actions/checkout@v4
- name: 🔧 setup tox-uv
uses: ./.github/tox-uv
- name: 🧪 tox -e ${{ matrix.tox_env }}
run: uv run tox -e ${{ matrix.tox_env }}
- name: "🐔 codecov: upload test coverage"
uses: codecov/[email protected]
with:
flags: ${{ matrix.tox_env }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: 📥 checkout
uses: actions/checkout@v4
- name: 🔧 setup tox-uv
uses: ./.github/tox-uv
- name: 🧪 tox -e ${{ matrix.tox_env }}
run: uv run tox -e ${{ matrix.tox_env }}
- name: "🐔 codecov: upload test coverage"
uses: codecov/[email protected]
with:
flags: ${{ matrix.tox_env }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Ruff:
runs-on: ubuntu-latest
steps:
- name: 📥 checkout
uses: actions/checkout@v4
- name: 🔧 setup uv
uses: ./.github/uv
- name: 🐶 ruff
run: uv run ruff check
- name: 📥 checkout
uses: actions/checkout@v4
- name: 🔧 setup uv
uses: ./.github/uv
- name: 🐶 ruff
run: uv run ruff check
36 changes: 24 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ dev = [
"aiosqlite>=0.20.0",
"python-semantic-release>=9.8.8",
"twine>=5.1.1",
"pdbpp>=0.11.7",
]

[tool.uv.sources]
Expand Down Expand Up @@ -100,15 +101,26 @@ mode = "init"
changelog_file = "./docs/changelog.md"

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = { default, sqlmodel }

[testenv]
passenv = CI
runner = uv-venv-lock-runner
commands =
pytest --cov fastsqla --cov-report=term-missing --cov-report=xml
extras:
sqlmodel: sqlmodel
"""
envlist = ["sqlmodel", "fastapi-pre121", "fastapi-post121"]

[tool.tox.env_run_base]
runner = "uv-venv-runner"
commands = [
[
"pytest",
"--cov",
"fastsqla",
"--cov-report=term-missing",
"--cov-report=xml",
],
]
allowlist_externals = ["pytest", "pip"]

[tool.tox.env.sqlmodel]
extras = ["sqlmodel"]

[tool.tox.env.fastapi-pre121]
commands_pre = [["pip", "install", "-U", "fastapi<0.121"]]

[tool.tox.env.fastapi-post121]
commands_pre = [["pip", "install", "-U", "fastapi>=0.121"]]
14 changes: 12 additions & 2 deletions src/fastsqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from contextlib import _AsyncGeneratorContextManager, asynccontextmanager
from typing import Annotated, Generic, TypeVar, TypedDict

from fastapi import Depends, FastAPI, Query
from fastapi import Depends as BaseDepends
from fastapi import FastAPI, Query
from pydantic import BaseModel, Field
from sqlalchemy import Result, Select, func, select
from sqlalchemy.ext.asyncio import (
Expand Down Expand Up @@ -44,6 +45,15 @@
logger = get_logger(__name__)


def Depends(*args, **kwargs):
"Allow backward compatibility with fastapi<0.121"
try:
return BaseDepends(*args, **kwargs)
except TypeError:
kwargs.pop("scope")
return BaseDepends(*args, **kwargs)


class Base(DeclarativeBase, DeferredReflection):
"""Inherit from `Base` to declare an `SQLAlchemy` model.

Expand Down Expand Up @@ -252,7 +262,7 @@ async def new_session() -> AsyncGenerator[AsyncSession, None]:
yield session


Session = Annotated[AsyncSession, Depends(new_session)]
Session = Annotated[AsyncSession, Depends(new_session, scope="function")]
"""Dependency used exclusively in endpoints to get an `SQLAlchemy` or `SQLModel` session.

`Session` is a [`FastAPI` dependency](https://fastapi.tiangolo.com/tutorial/dependencies/)
Expand Down
48 changes: 47 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.