def paginate_query(statement, page, page_size):
    """Returns paginated statement if page is provided, otherwise returns
    the same statement."""

    if page is not None and page_size is not None:
        statement = statement.offset(page * page_size).limit(page_size)

    return statement