Spaces:
Sleeping
Sleeping
from fastapi import FastAPI | |
from fastapi.responses import JSONResponse | |
from fastapi.requests import Request | |
from fastapi.security.utils import get_authorization_scheme | |
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession | |
from sqlalchemy.orm import sessionmaker | |
from api.models import Base | |
from api.schemas import User, Team | |
from api.crud import user, team | |
app = FastAPI() | |
engine = create_async_engine("sqlite:///database.db") | |
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False) | |
async def startup(): | |
async with engine.begin() as conn: | |
await conn.run_sync(Base.metadata.create_all) | |
async def create_user(user: User): | |
return await user.create() | |
async def create_team(team: Team): | |
return await team.create() | |
async def read_users(): | |
return await user.read_all() | |
async def read_teams(): | |
return await team.read_all() | |
async def read_user(user_id: int): | |
return await user.read_one(user_id) | |
async def read_team(team_id: int): | |
return await team.read_one(team_id) | |
async def update_user(user_id: int, user: User): | |
return await user.update(user_id, user) | |
async def update_team(team_id: int, team: Team): | |
return await team.update(team_id, team) | |
async def delete_user(user_id: int): | |
return await user.delete(user_id) | |
async def delete_team(team_id: int): | |
return await team.delete(team_id) |