A small utility to paginate SqlAlchemy queries..
Just do:
$ pip install git+ssh://[email protected]/wizeline/sqlalchemy-pagination.git
Just import the paginate method and call it with the query, the current page and the page size
from sqlalchemy_pagination import paginate
page = paginate(session.query(User), 1, 25)
The pagination objects has the following attributes
items
: The items of the current page base on the querytotal
: Total number of itemspages
: Total number of pageshas_next
: Boolean indication wether there are more pages to fetchhas_previous
: Boolean indicating wether there are previous pagesnext_page
: Next page number or None if the current page is the last oneprevious_page
: Previous page number or None if the current page is the last one
First install Python 3 from Homebrew and virtualenvwrapper:
brew install python3
pip3 install virtualenv virtualenvwrapper
After installing virtualenvwrapper please add the following line to your shell startup file (e.g. ~/.zshrc):
source /usr/local/bin/virtualenvwrapper.sh
Then reset your terminal.
Clone this respository and create the virtual environment:
$ git clone https://github.com/wizeline/sqlalchemy-pagination
$ cd sqlalchemy-pagination
$ mkvirtualenv sqlalchemy-pagination
$ workon sqlalchemy-pagination
$ pip install -r requirements-dev.txt
$ pip install tox
To run the tests, you just do:
$ tox
We use editorconfig
to define our coding style. Please add editorconfig
to your editor of choice.
When running tox
linting will also be run along with the tests. You can also run linting only by doing:
$ tox -e flake8