Adding top-level Scopes table
This commit is contained in:
1 parent
bc8b67d585
commit
3febc15a8f
11 files changed
+470
-1
No files matched your search
@@ -31,6 +31,30 @@ async def list_all(
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def list_by_part_type(
|
||||
db: AsyncSession, part_type_id: int, skip: int = 0, limit: int = 1000
|
||||
) -> list[AugmentedPart]:
|
||||
"""All augmented parts of a given part type, ordered by description."""
|
||||
result = await db.execute(
|
||||
select(AugmentedPart)
|
||||
.where(AugmentedPart.part_type_id == part_type_id)
|
||||
.order_by(AugmentedPart.description)
|
||||
.offset(skip)
|
||||
.limit(limit)
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def get_many(db: AsyncSession, ids: list[int]) -> list[AugmentedPart]:
|
||||
"""Fetch augmented parts by id in one query (selectin relationships loaded)."""
|
||||
if not ids:
|
||||
return []
|
||||
result = await db.execute(
|
||||
select(AugmentedPart).where(AugmentedPart.id.in_(ids))
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def list_filtered(
|
||||
db: AsyncSession,
|
||||
description: str = "",
|
||||
|
||||
@@ -52,6 +52,29 @@ async def list_for_part(db: AsyncSession, augmented_part_id: int) -> list[Fit]:
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def list_for_parts(
|
||||
db: AsyncSession,
|
||||
part_ids: list[int],
|
||||
exclude_label: FitLabel | None = None,
|
||||
) -> list[Fit]:
|
||||
"""All fits touching any of the given augmented parts, in one query.
|
||||
|
||||
Pass ``exclude_label`` to drop, e.g., confirmed non-fits (``FitLabel.NONE``).
|
||||
"""
|
||||
if not part_ids:
|
||||
return []
|
||||
q = select(Fit).where(
|
||||
or_(
|
||||
Fit.augmented_part_a_id.in_(part_ids),
|
||||
Fit.augmented_part_b_id.in_(part_ids),
|
||||
)
|
||||
)
|
||||
if exclude_label is not None:
|
||||
q = q.where(Fit.label != exclude_label)
|
||||
result = await db.execute(q.order_by(Fit.id))
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def list_all(
|
||||
db: AsyncSession,
|
||||
skip: int = 0,
|
||||
|
||||
@@ -17,6 +17,20 @@ async def get_by_augmented_part(
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def list_by_augmented_parts(
|
||||
db: AsyncSession, augmented_part_ids: list[int]
|
||||
) -> list[ScopeInfo]:
|
||||
"""ScopeInfo rows for the given augmented parts, fetched in one query."""
|
||||
if not augmented_part_ids:
|
||||
return []
|
||||
result = await db.execute(
|
||||
select(ScopeInfo).where(
|
||||
ScopeInfo.augmented_part_id.in_(augmented_part_ids)
|
||||
)
|
||||
)
|
||||
return list(result.scalars().all())
|
||||
|
||||
|
||||
async def create(
|
||||
db: AsyncSession,
|
||||
*,
|
||||
|
||||
Reference in new issue
Block a user