Adding ISOThread and UNC Thread
This commit is contained in:
1 parent
9285a021c0
commit
35e8a61b1d
22 files changed
+796
-3
No files matched your search
@@ -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()
|
||||
@@ -0,0 +1,48 @@
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.unc_thread import UncSeries, UncThread
|
||||
|
||||
|
||||
async def get(db: AsyncSession, unc_thread_id: int) -> UncThread | None:
|
||||
return await db.get(UncThread, unc_thread_id)
|
||||
|
||||
|
||||
async def list_all(db: AsyncSession, skip: int = 0, limit: int = 100) -> list[UncThread]:
|
||||
result = await db.execute(
|
||||
select(UncThread).order_by(UncThread.id).offset(skip).limit(limit)
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def create(
|
||||
db: AsyncSession,
|
||||
*,
|
||||
diameter_fraction: str,
|
||||
tpi: int,
|
||||
series: UncSeries,
|
||||
depth_in: float | None = None,
|
||||
) -> UncThread:
|
||||
thread = UncThread(
|
||||
diameter_fraction=diameter_fraction,
|
||||
tpi=tpi,
|
||||
series=series,
|
||||
depth_in=depth_in,
|
||||
)
|
||||
db.add(thread)
|
||||
await db.commit()
|
||||
await db.refresh(thread)
|
||||
return thread
|
||||
|
||||
|
||||
async def update(db: AsyncSession, thread: UncThread, data: dict) -> UncThread:
|
||||
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: UncThread) -> None:
|
||||
await db.delete(thread)
|
||||
await db.commit()
|
||||
Reference in new issue
Block a user