27 lines
606 B
Python
27 lines
606 B
Python
|
"""This module contains common utilities for handling models."""
|
||
|
|
||
|
import enum
|
||
|
from typing import Callable
|
||
|
|
||
|
import sqlalchemy
|
||
|
|
||
|
|
||
|
class SortOrder(enum.Enum):
|
||
|
"""Possible sort orders for database queries."""
|
||
|
|
||
|
asc = 'asc'
|
||
|
ASC = 'asc'
|
||
|
desc = 'desc'
|
||
|
DESC = 'desc'
|
||
|
|
||
|
@property
|
||
|
def call(self) -> Callable:
|
||
|
"""Returns the sqlalchemy sort function depending on the instance value."""
|
||
|
|
||
|
if self.value == 'asc':
|
||
|
return sqlalchemy.asc
|
||
|
elif self.value == 'desc':
|
||
|
return sqlalchemy.desc
|
||
|
else:
|
||
|
raise RuntimeError("Logic error.")
|