mirror of
https://github.com/creyD/creyPY.git
synced 2026-04-13 03:40:31 +02:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f24db62781 | |||
| 4d997a375e |
@@ -36,7 +36,7 @@ def update_obj_from_data(
|
|||||||
model: Type[T],
|
model: Type[T],
|
||||||
id: UUID | str,
|
id: UUID | str,
|
||||||
db: Session,
|
db: Session,
|
||||||
partial: bool = False,
|
partial: bool = False, # TODO: inverse, because it is currently the wrong way around
|
||||||
ignore_fields=[],
|
ignore_fields=[],
|
||||||
additional_data={},
|
additional_data={},
|
||||||
exclude={},
|
exclude={},
|
||||||
|
|||||||
15
creyPY/fastapi/order_by.py
Normal file
15
creyPY/fastapi/order_by.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from typing import Callable
|
||||||
|
|
||||||
|
from pydantic.json_schema import SkipJsonSchema
|
||||||
|
from sqlalchemy import asc, desc
|
||||||
|
from sqlalchemy.sql.selectable import Select
|
||||||
|
|
||||||
|
|
||||||
|
def order_by(order_by: str | SkipJsonSchema[None] = None) -> Callable[[Select], Select]:
|
||||||
|
def _order_by(query: Select) -> Select:
|
||||||
|
if order_by:
|
||||||
|
direction = desc if order_by.startswith("-") else asc
|
||||||
|
query = query.order_by(direction(order_by.lstrip("-")))
|
||||||
|
return query
|
||||||
|
|
||||||
|
return _order_by
|
||||||
Reference in New Issue
Block a user