Skip to content

Commit

Permalink
Rename the param 'query' to 'stmt' in functions apply_filters, apply_…
Browse files Browse the repository at this point in the history
…loads and apply_sort
  • Loading branch information
slymit committed Jun 13, 2024
1 parent 14eaff0 commit 26aa462
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions sa_filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ def get_named_models(filters):


def apply_filters(
query: Union[Select, Query],
stmt: Union[Select, Query],
filter_spec: Union[Iterable[Dict[str, Any]], Dict[str, Any]],
do_auto_join: bool = True
) -> Union[Select, Query]:
"""Apply filters to a SQLAlchemy query or Select object.
:param query:
:param stmt:
The statement to be processed. May be one of:
a :class:`sqlalchemy.sql.Select` object or
a :class:`sqlalchemy.orm.Query` object.
Expand Down Expand Up @@ -248,18 +248,18 @@ def apply_filters(
"""
filters = build_filters(filter_spec)

default_model = get_default_model(query)
default_model = get_default_model(stmt)

filter_models = get_named_models(filters)
if do_auto_join:
query = auto_join(query, *filter_models)
stmt = auto_join(stmt, *filter_models)

sqlalchemy_filters = [
filter.format_for_sqlalchemy(query, default_model)
filter.format_for_sqlalchemy(stmt, default_model)
for filter in filters
]

if sqlalchemy_filters:
query = query.filter(*sqlalchemy_filters)
stmt = stmt.filter(*sqlalchemy_filters)

return query
return stmt
14 changes: 7 additions & 7 deletions sa_filters/loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def get_named_models(loads):


def apply_loads(
query: Union[Select, Query],
stmt: Union[Select, Query],
load_spec: Union[List[Dict[str, Any]], Dict[str, Any], List[str]]
) -> Union[Select, Query]:
"""Apply load restrictions to a :class:`sqlalchemy.sql.Select` object
or a :class:`sqlalchemy.orm.Query` object.
:param query:
:param stmt:
The statement to be processed.
:param load_spec:
Expand Down Expand Up @@ -90,15 +90,15 @@ def apply_loads(

loads = [LoadOnly(item) for item in load_spec]

default_model = get_default_model(query)
default_model = get_default_model(stmt)

load_models = get_named_models(loads)
query = auto_join(query, *load_models)
stmt = auto_join(stmt, *load_models)

sqlalchemy_loads = [
load.format_for_sqlalchemy(query, default_model) for load in loads
load.format_for_sqlalchemy(stmt, default_model) for load in loads
]
if sqlalchemy_loads:
query = query.options(*sqlalchemy_loads)
stmt = stmt.options(*sqlalchemy_loads)

return query
return stmt
14 changes: 7 additions & 7 deletions sa_filters/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def get_named_models(sorts):


def apply_sort(
query: Union[Select, Query],
stmt: Union[Select, Query],
sort_spec: Union[List[Dict[str, Any]], Dict[str, Any]]
) -> Union[Select, Query]:
"""Apply sorting to a SQLAlchemy :class:`sqlalchemy.sql.Select`
object or a :class:`sqlalchemy.orm.Query` object.
:param query:
:param stmt:
The statement to be processed.
:param sort_spec:
Expand Down Expand Up @@ -118,16 +118,16 @@ def apply_sort(

sorts = [Sort(item) for item in sort_spec]

default_model = get_default_model(query)
default_model = get_default_model(stmt)

sort_models = get_named_models(sorts)
query = auto_join(query, *sort_models)
stmt = auto_join(stmt, *sort_models)

sqlalchemy_sorts = [
sort.format_for_sqlalchemy(query, default_model) for sort in sorts
sort.format_for_sqlalchemy(stmt, default_model) for sort in sorts
]

if sqlalchemy_sorts:
query = query.order_by(*sqlalchemy_sorts)
stmt = stmt.order_by(*sqlalchemy_sorts)

return query
return stmt

0 comments on commit 26aa462

Please sign in to comment.