title: Implement pagination without flask-sqlalchemy
body: <p>I would like to remove the dependence of <code>flask-SQLAlchemy</code> from my application. Although, I rely pretty heavily on the <code>pagination</code> functionality that comes with the library. I would like to move the pagination ability to my models.</p>
  
  <p>Looking inside <code>flask-SQLAlchemy</code>, I see the following:</p>
  
  <pre><code>class Paginate(object):
      def __init__(self, query, page, per_page, total, items):
  
      @property
      def pages(self):
          """The total number of pages"""
          if self.per_page == 0:
              pages = 0
          else:
              pages = int(ceil(self.total / float(self.per_page)))
          return pages
      ...
  
  class BaseQuery(orm.Query):
      ...
      def paginate(self, page=None, per_page=None, error_out=True):
          ...
          return Pagination(self, page, per_page, total, items)
  </code></pre>
  
  <p>This functionality is called like below:</p>
  
  <pre><code>page = Model.query.filter(*where_to_SQL(Model, where)).paginate(page=1, per_page=chunksize)
  </code></pre>
  
  <p>If I have defined my <code>SQLAlchemy</code> declarative model as below, how might I add pagination with a minimal change to my codebase?</p>
  
  <p>in <code>database.core.py</code>, from where the <code>Model</code> class is imported and used in model definitions...</p>
  
  <pre><code>...
  Model = declarative_base(name='Model')
  Model.query = db_session.query_property()
  ...
  </code></pre>