Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /fastapi-users_fastapi-users /docs /src /db_sqlalchemy_oauth.py
| from collections.abc import AsyncGenerator | |
| from fastapi import Depends | |
| from fastapi_users.db import ( | |
| SQLAlchemyBaseOAuthAccountTableUUID, | |
| SQLAlchemyBaseUserTableUUID, | |
| SQLAlchemyUserDatabase, | |
| ) | |
| from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine | |
| from sqlalchemy.orm import DeclarativeBase, Mapped, relationship | |
| DATABASE_URL = "sqlite+aiosqlite:///./test.db" | |
| class Base(DeclarativeBase): | |
| pass | |
| class OAuthAccount(SQLAlchemyBaseOAuthAccountTableUUID, Base): | |
| pass | |
| class User(SQLAlchemyBaseUserTableUUID, Base): | |
| oauth_accounts: Mapped[list[OAuthAccount]] = relationship( | |
| "OAuthAccount", lazy="joined" | |
| ) | |
| engine = create_async_engine(DATABASE_URL) | |
| async_session_maker = async_sessionmaker(engine, expire_on_commit=False) | |
| async def create_db_and_tables(): | |
| async with engine.begin() as conn: | |
| await conn.run_sync(Base.metadata.create_all) | |
| async def get_async_session() -> AsyncGenerator[AsyncSession, None]: | |
| async with async_session_maker() as session: | |
| yield session | |
| async def get_user_db(session: AsyncSession = Depends(get_async_session)): | |
| yield SQLAlchemyUserDatabase(session, User, OAuthAccount) | |
Xet Storage Details
- Size:
- 1.21 kB
- Xet hash:
- 55202e970c804cc7e2ed927d0dd3b26836611f4d1101c2acc72425dd107156df
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.