Adding ISOThread and UNC Thread

This commit is contained in:
Ian Roddis committed 2026-06-24 21:58:15 -03:00
1 parent 9285a021c0
commit 35e8a61b1d
22 files changed
+796 -3

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.iso_thread import IsoThread
async def get(db: AsyncSession, iso_thread_id: int) -> IsoThread | None:
return await db.get(IsoThread, iso_thread_id)
async def list_all(db: AsyncSession, skip: int = 0, limit: int = 100) -> list[IsoThread]:
result = await db.execute(
select(IsoThread).order_by(IsoThread.id).offset(skip).limit(limit)
)
return list(result.scalars().all())
async def create(
db: AsyncSession,
*,
diameter_mm: float,
pitch_mm: float,
depth_mm: float | None = None,
) -> IsoThread:
thread = IsoThread(diameter_mm=diameter_mm, pitch_mm=pitch_mm, depth_mm=depth_mm)
db.add(thread)
await db.commit()
await db.refresh(thread)
return thread
async def update(db: AsyncSession, thread: IsoThread, data: dict) -> IsoThread:
for field, value in data.items():
setattr(thread, field, value)
await db.commit()
await db.refresh(thread)
return thread
async def delete(db: AsyncSession, thread: IsoThread) -> None:
await db.delete(thread)
await db.commit()