netadm/models/user.py

24 lines
730 B
Python
Raw Permalink Normal View History

2024-10-02 09:50:08 +00:00
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import BigInteger
2024-10-02 08:47:11 +00:00
from config import settings
from models import Base
from models.mixins import IdIntPkMixin
from fastapi_users_db_sqlalchemy import (
SQLAlchemyBaseUserTable,
SQLAlchemyUserDatabase,
)
2024-10-02 15:50:50 +00:00
from typing import TYPE_CHECKING, Optional
2024-10-02 08:47:11 +00:00
if TYPE_CHECKING:
from sqlalchemy.ext.asyncio import AsyncSession
2024-10-02 09:50:08 +00:00
class User(Base, IdIntPkMixin, SQLAlchemyBaseUserTable[settings.type.UserIdType]):
2024-10-02 15:50:50 +00:00
name: Mapped[Optional[str]] = mapped_column(nullable=True)
tg_id: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True)
2024-10-02 08:47:11 +00:00
@classmethod
def get_db(cls, session: "AsyncSession"):
return SQLAlchemyUserDatabase(session, cls)