Skip to main content

pypaginate.adapters.sqlalchemy.sorting

Translate sort specs into SQLAlchemy ORDER BY clauses.

Maps each SortSpec to a directed column expression with null placement, applying .asc() / .desc() and .nulls_first() / .nulls_last().

build_order_by

def build_order_by(model: type, sorting: Sequence[SortSpec]) -> list[Any]

Translate sorting into an ordered list of ORDER BY clauses.

Arguments:

  • model - The declarative ORM model the fields belong to.
  • sorting - Sort specifications, applied in order.

Returns:

A list of SQLAlchemy order expressions for Select.order_by.