Skip to content

Commit 689dc38

Browse files
committed
perf: Supports filter types EmailStr,UUID,IPvAnyAddress.
1 parent a1e3fab commit 689dc38

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

fastapi_amis_admin/crud/_sqlmodel.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
Type,
1414
Union,
1515
)
16+
from uuid import UUID
1617

1718
from fastapi import APIRouter, Body, Depends, Query
1819
from fastapi.encoders import DictIntStrAny, SetIntStr
19-
from pydantic import Extra, Json
20+
from pydantic import EmailStr, Extra, IPvAnyAddress, Json
2021
from pydantic.fields import ModelField
2122
from pydantic.utils import ValueItems
2223
from sqlalchemy import Column, Table, func
@@ -288,7 +289,7 @@ def _create_schema_filter(self) -> Type[SchemaFilterT]:
288289
for modelfield in modelfields:
289290
if not issubclass(modelfield.type_, (Enum, bool)) and issubclass(
290291
modelfield.type_,
291-
(int, float, datetime.datetime, datetime.date, datetime.time, Json),
292+
(int, float, datetime.datetime, datetime.date, datetime.time, Json, EmailStr, IPvAnyAddress, UUID),
292293
):
293294
modelfield.type_ = str
294295
modelfield.outer_type_ = str
@@ -447,7 +448,7 @@ async def depend(
447448
item_id: List[str] = Depends(parser_item_id),
448449
stmt: Select = Depends(self._select_maker),
449450
):
450-
filtered_id = await self.db.async_scalars(stmt.where(self.pk.in_(item_id)).with_only_columns([self.pk]))
451+
filtered_id = await self.db.async_scalars(stmt.where(self.pk.in_(item_id)).with_only_columns(self.pk))
451452
return filtered_id.all()
452453

453454
return depend
@@ -469,7 +470,7 @@ async def route(
469470
stmt = stmt.filter(*self.calc_filter_clause(data.filters))
470471
if paginator.show_total:
471472
data.total = await self.db.async_scalar(
472-
select(func.count("*")).select_from(stmt.with_only_columns([self.pk]).subquery())
473+
select(func.count("*")).select_from(stmt.with_only_columns(self.pk).subquery())
473474
)
474475
orderBy = self._calc_ordering(paginator.orderBy, paginator.orderDir)
475476
if orderBy:

0 commit comments

Comments
 (0)