Implemented find queries

This commit is contained in:
Donkie
2023-04-05 21:29:39 +02:00
parent 6a58caa2ec
commit b51d0a3183
6 changed files with 199 additions and 25 deletions

View File

@@ -2,6 +2,7 @@
from typing import Optional
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from spoolman.database import models
@@ -32,6 +33,20 @@ async def get_by_id(db: AsyncSession, vendor_id: int) -> models.Vendor:
return vendor
async def find(
*,
db: AsyncSession,
name: Optional[str] = None,
) -> list[models.Vendor]:
"""Find a list of vendor objects by search criteria."""
stmt = select(models.Vendor)
if name is not None:
stmt = stmt.where(models.Vendor.name.ilike(f"%{name}%"))
rows = await db.execute(stmt)
return list(rows.scalars().all())
async def update(
*,
db: AsyncSession,