You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

32 lines
1.1 KiB

from __future__ import annotations
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.entities import PlacementPolicy
class PlacementPolicyRepository:
def __init__(self, session: AsyncSession) -> None:
self.session = session
async def get_by_file_class(self, file_class: str) -> PlacementPolicy | None:
result = await self.session.execute(
select(PlacementPolicy).where(PlacementPolicy.file_class == file_class)
)
return result.scalar_one_or_none()
async def list_all(self) -> list[PlacementPolicy]:
result = await self.session.execute(select(PlacementPolicy).order_by(PlacementPolicy.file_class.asc()))
return list(result.scalars().all())
async def create(self, policy: PlacementPolicy) -> PlacementPolicy:
self.session.add(policy)
await self.session.flush()
await self.session.refresh(policy)
return policy
async def save(self, policy: PlacementPolicy) -> PlacementPolicy:
await self.session.flush()
await self.session.refresh(policy)
return policy