Query queries are used in SQLAlchemy, and basequery queries are used in Flask-sqlalchemy, and they are the relationships between subclasses and parent classes
Suppose page_index=1,page_size=10; All paged queries cannot be followed by first (), all (), etc.
1.sets the index offset with offset (), limit () limits the amount taken
Db.session.query (User.Name). Filter (User.email.like ('%'+email+'% ')). Limit (page_size). Offset ((page_index-1) *page_size)#Thefilter statement can be followed by the order_by statement
2. Use Slice (offset, amount of removal ) function
Db.session.query (User.Name). Filter (User.email.like ('%'+email+'% ')). Slice ((page_index-1) * page_size, Page_index * page_size)#Thefilter statement can be followed by the order_by statement
Note: This method has the same effect as the first.
Because: By the internal method, the first property of the slice () function is the value of the offset () function, and the second property is the value of the limit () function.
@_generative(_no_statement_condition)
def slice(self, start, stop):
"""apply LIMIT/OFFSET to the ``Query`` based on a "
"range and return the newly resulting ``Query``."""
if start is not None and stop is not None:
self._offset = (self._offset or 0) + start
self._limit = stop - start
elif start is None and stop is not None:
self._limit = stop
elif start is not None and stop is None:
self._offset = (self._offset or 0) + start
if self._offset == 0:
self._offset = None
@_generative(_no_statement_condition)
def limit(self, limit):
"""Apply a ``LIMIT`` to the query and return the newly resulting
``Query``.
"""
self._limit = limit
@_generative(_no_statement_condition)
def offset(self, offset):
"""Apply an ``OFFSET`` to the query and return the newly resulting
``Query``.
"""
self._offset = offset
3. Use Paginate (offset, amount of removal function for Basequery
User_obj=user.query.filter (User.email.like ('%'+email+'%' ) . paginate (int (page_index), int (page_size), False)#object_list =user_ Obj.items
4.use limit in filter
Db.session.query (User.Name). Filter (User.email.like ('%'+email+'% ' and limit (page_index-1) * page_size, page_size)# here can not be followed order_by statement, otherwise error
Http://www.cnblogs.com/rgcLOVEyaya/p/RGC_LOVE_YAYA_350days.html
Several pagination methods of SQLAlchemy and Flask-sqlalchemy