poetry add 'fastapi-users[sqlalchemy]'

This commit is contained in:
s.mostryukov 2024-10-02 11:47:11 +03:00
parent 8ec2ed1ebd
commit 541e35bc51
6 changed files with 51 additions and 2 deletions

View File

@ -1,3 +1,5 @@
from typing import ClassVar
from pydantic import BaseModel from pydantic import BaseModel
from pydantic_settings import ( from pydantic_settings import (
BaseSettings, BaseSettings,
@ -45,6 +47,10 @@ class DatabaseConfig(BaseModel):
} }
class TypesConfig(BaseModel):
UserIdType: ClassVar = int
class Settings(BaseSettings): class Settings(BaseSettings):
model_config = SettingsConfigDict( model_config = SettingsConfigDict(
env_file=( env_file=(
@ -58,6 +64,7 @@ class Settings(BaseSettings):
run: RunConfig run: RunConfig
swagger: SwaggerConfig = SwaggerConfig() swagger: SwaggerConfig = SwaggerConfig()
db: DatabaseConfig db: DatabaseConfig
type: TypesConfig = TypesConfig()
settings = Settings() settings = Settings()

View File

@ -1,8 +1,11 @@
from .db_helper import db_helper from .db_helper import db_helper
from .base import Base from .base import Base
from .user import User
__all__ = ( __all__ = (
"db_helper", "db_helper",
"Base", "Base",
"User",
) )

View File

@ -0,0 +1,4 @@
from .id_int_pk import IdIntPkMixin
__all__ = ("IdIntPkMixin",)

19
models/user.py Normal file
View File

@ -0,0 +1,19 @@
from config import settings
from models import Base
from models.mixins import IdIntPkMixin
from fastapi_users_db_sqlalchemy import (
SQLAlchemyBaseUserTable,
SQLAlchemyUserDatabase,
)
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from sqlalchemy.ext.asyncio import AsyncSession
class User(Base, IdIntPkMixin, SQLAlchemyBaseUserTable[settings.types.UserIdType]):
@classmethod
def get_db(cls, session: "AsyncSession"):
return SQLAlchemyUserDatabase(session, cls)

18
poetry.lock generated
View File

@ -467,6 +467,7 @@ files = [
[package.dependencies] [package.dependencies]
email-validator = ">=1.1.0,<2.2" email-validator = ">=1.1.0,<2.2"
fastapi = ">=0.65.2" fastapi = ">=0.65.2"
fastapi-users-db-sqlalchemy = {version = ">=6.0.0", optional = true, markers = "extra == \"sqlalchemy\""}
makefun = ">=1.11.2,<2.0.0" makefun = ">=1.11.2,<2.0.0"
pwdlib = {version = "0.2.0", extras = ["argon2", "bcrypt"]} pwdlib = {version = "0.2.0", extras = ["argon2", "bcrypt"]}
pyjwt = {version = "2.8.0", extras = ["crypto"]} pyjwt = {version = "2.8.0", extras = ["crypto"]}
@ -478,6 +479,21 @@ oauth = ["httpx-oauth (>=0.13)"]
redis = ["redis (>=4.3.3,<6.0.0)"] redis = ["redis (>=4.3.3,<6.0.0)"]
sqlalchemy = ["fastapi-users-db-sqlalchemy (>=6.0.0)"] sqlalchemy = ["fastapi-users-db-sqlalchemy (>=6.0.0)"]
[[package]]
name = "fastapi-users-db-sqlalchemy"
version = "6.0.1"
description = "FastAPI Users database adapter for SQLAlchemy"
optional = false
python-versions = ">=3.8"
files = [
{file = "fastapi_users_db_sqlalchemy-6.0.1-py3-none-any.whl", hash = "sha256:d1050ec31eb75e8c4fa9abafa4addaf0baf5c97afeea2f0f910ea55e2451fcad"},
{file = "fastapi_users_db_sqlalchemy-6.0.1.tar.gz", hash = "sha256:f0ef9fe3250453712d25c13170700c80fa205867ce7add7ef391c384ec27cbe1"},
]
[package.dependencies]
fastapi-users = ">=10.0.0"
sqlalchemy = {version = ">=2.0.0,<2.1.0", extras = ["asyncio"]}
[[package]] [[package]]
name = "greenlet" name = "greenlet"
version = "3.1.1" version = "3.1.1"
@ -1520,4 +1536,4 @@ files = [
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.12" python-versions = "^3.12"
content-hash = "756f4a7bf70e40c6b8dadeba9156c8b3e980f3ee5f14d73c9571cc6597cd52ce" content-hash = "48335dd82829883c1d2ac4b19b8ae09d8455bf3b9add9aa6bd83bb07e61336f2"

View File

@ -15,7 +15,7 @@ jinja2 = "^3.1.4"
alembic = "^1.13.3" alembic = "^1.13.3"
asyncpg = "^0.29.0" asyncpg = "^0.29.0"
sqlalchemy = {extras = ["asyncio"], version = "^2.0.35"} sqlalchemy = {extras = ["asyncio"], version = "^2.0.35"}
fastapi-users = "^13.0.0" fastapi-users = {extras = ["sqlalchemy"], version = "^13.0.0"}