Code Monkey home page Code Monkey logo

sqlalchemy-pagination's Introduction

sqlalchemy-pagination

Build Status

Contents

  1. About
  2. Install
  3. Usage
  4. Hacking
    1. Setup
    2. Testing
    3. Coding conventions

About

A small utility to paginate SqlAlchemy queries..

Install

Just do:

$ pip install git+ssh://[email protected]/wizeline/sqlalchemy-pagination.git

Usage

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 query
  • total: Total number of items
  • pages: Total number of pages
  • has_next: Boolean indication wether there are more pages to fetch
  • has_previous: Boolean indicating wether there are previous pages
  • next_page: Next page number or None if the current page is the last one
  • previous_page: Previous page number or None if the current page is the last one

Hacking

Setup

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 -p python3 sqlalchemy-pagination
$ workon sqlalchemy-pagination
$ pip install -r requirements-dev.txt
$ pip install tox

Testing

To run the tests, you just do:

$ tox

Coding conventions

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

sqlalchemy-pagination's People

Contributors

albertein avatar pabloariasperez avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.