Files
ormar/ormar/queryset/queries/offset_query.py
Ethon 6e2a2ad129 Queryset mixins (#629)
* add enum field

* add decorator for asyncio

* fix enum typing, additional tests, add docs

* add more tests

* query-mixin

* use dict to replace ordereddict

Co-authored-by: collerek <collerek@gmail.com>
2022-05-07 14:02:30 +02:00

26 lines
643 B
Python

from typing import Optional
import sqlalchemy
class OffsetQuery:
"""
Modifies the select query with offset if set
"""
def __init__(self, query_offset: Optional[int]) -> None:
self.query_offset = query_offset
def apply(self, expr: sqlalchemy.sql.select) -> sqlalchemy.sql.select:
"""
Applies the offset clause.
:param expr: query to modify
:type expr: sqlalchemy.sql.selectable.Select
:return: modified query
:rtype: sqlalchemy.sql.selectable.Select
"""
if self.query_offset:
expr = expr.offset(self.query_offset)
return expr