Skip to main content

pypaginate.adapters.sqlalchemy.filters

Translate filter specs into SQLAlchemy boolean expressions.

Maps each FilterSpec.operator wire-string to a column-expression builder and combines specs either as a flat list (each spec carries its own AND/OR logic) or as a nested :class:~pypaginate.specs.FilterGroup (recursing with and_/or_).

build_filter

def build_filter(model: type, filters: Sequence[FilterSpec]) -> Any | None

Combine flat filters into one boolean expression (None if empty).

Each spec's logic selects its group: AND-specs are conjoined, OR-specs are disjoined, and the two groups are then conjoined — (a AND b) AND (c OR d).

Arguments:

  • model - The declarative ORM model the fields belong to.
  • filters - Flat filter specifications to translate.

Returns:

A SQLAlchemy boolean expression, or None when filters is empty.

build_filter_group

def build_filter_group(model: type, group: FilterGroup) -> Any

Translate a nested And / Or group into a boolean expression.

Arguments:

  • model - The declarative ORM model the fields belong to.
  • group - A (possibly nested) filter group.

Returns:

A SQLAlchemy boolean expression combining every child condition.