26 lines
629 B
Python
26 lines
629 B
Python
from typing import Sequence
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from sqlalchemy.orm import joinedload, selectinload
|
|
|
|
from models import Isp
|
|
from schemas.isp import IspCreate, IspRead
|
|
|
|
|
|
async def get_all_isp(
|
|
session: AsyncSession,
|
|
) -> Sequence[Isp]:
|
|
stmt = select(Isp).options(selectinload(Isp.isp_connections)).order_by(Isp.id)
|
|
result = await session.scalars(stmt)
|
|
|
|
return result.all()
|
|
|
|
|
|
async def create_isp(session: AsyncSession, isp_scheme: IspCreate) -> Isp:
|
|
isp = Isp(**isp_scheme.model_dump())
|
|
session.add(isp)
|
|
await session.commit()
|
|
return isp
|