Adding AttachmentPointNames
This commit is contained in:
1 parent
ae50ec7049
commit
2767fb1c8e
14 files changed
+406
-3
No files matched your search
@@ -0,0 +1,50 @@
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.attachment_point_name import AttachmentPointName
|
||||
|
||||
|
||||
async def get(db: AsyncSession, apn_id: int) -> AttachmentPointName | None:
|
||||
return await db.get(AttachmentPointName, apn_id)
|
||||
|
||||
|
||||
async def get_by_name(db: AsyncSession, name: str) -> AttachmentPointName | None:
|
||||
result = await db.execute(
|
||||
select(AttachmentPointName).where(AttachmentPointName.name == name)
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def list_all(
|
||||
db: AsyncSession, skip: int = 0, limit: int = 100
|
||||
) -> list[AttachmentPointName]:
|
||||
result = await db.execute(
|
||||
select(AttachmentPointName)
|
||||
.order_by(AttachmentPointName.name)
|
||||
.offset(skip)
|
||||
.limit(limit)
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def create(db: AsyncSession, *, name: str) -> AttachmentPointName:
|
||||
apn = AttachmentPointName(name=name)
|
||||
db.add(apn)
|
||||
await db.commit()
|
||||
await db.refresh(apn)
|
||||
return apn
|
||||
|
||||
|
||||
async def update(
|
||||
db: AsyncSession, apn: AttachmentPointName, data: dict
|
||||
) -> AttachmentPointName:
|
||||
for field, value in data.items():
|
||||
setattr(apn, field, value)
|
||||
await db.commit()
|
||||
await db.refresh(apn)
|
||||
return apn
|
||||
|
||||
|
||||
async def delete(db: AsyncSession, apn: AttachmentPointName) -> None:
|
||||
await db.delete(apn)
|
||||
await db.commit()
|
||||
Reference in new issue
Block a user