mirror of
https://github.com/creyD/creyPY.git
synced 2026-04-12 19:30:30 +02:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f24db62781 | |||
| 4d997a375e |
@@ -36,7 +36,7 @@ def update_obj_from_data(
|
||||
model: Type[T],
|
||||
id: UUID | str,
|
||||
db: Session,
|
||||
partial: bool = False,
|
||||
partial: bool = False, # TODO: inverse, because it is currently the wrong way around
|
||||
ignore_fields=[],
|
||||
additional_data={},
|
||||
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