# filter-sort-paginate

> This is a simple filter, sort and pagination module designed to work with ExpressJS like servers.

Latest version **0.2.0** (published 2014-09-15) · GPLv2 license · 0 weekly downloads

## Install

```sh
npm install filter-sort-paginate
pnpm add filter-sort-paginate
yarn add filter-sort-paginate
bun add filter-sort-paginate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2014-09-15 |
| First published | 2014-09-01 |
| Weekly downloads | 0 |
| License | GPLv2 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+8 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nathan A Sculli |
| Maintainers | scull7 |
| Keywords | filter, sort, paginate |

## Links

- npm: https://www.npmjs.com/package/filter-sort-paginate
- Repository: https://github.com/scull7/filter-sort-paginate
- Issues: https://github.com/scull7/filter-sort-paginate/issues
- npm.io page: https://npm.io/package/filter-sort-paginate

## Dependencies (3)

- [mysql](https://npm.io/package/mysql.md) ^2.4.3
- [bluebird](https://npm.io/package/bluebird.md) ^2.3.2
- [mongoose](https://npm.io/package/mongoose.md) ^3.8.16

## Recent versions

- 0.2.0 (latest) — 2014-09-15
- 0.1.2 — 2014-09-01
- 0.0.0 — 2014-09-01

## README

[![Build Status](https://travis-ci.org/scull7/filter-sort-paginate.svg?branch=master)](https://travis-ci.org/scull7/filter-sort-paginate)
[![Coverage Status](https://img.shields.io/coveralls/scull7/filter-sort-paginate.svg)](https://coveralls.io/r/scull7/filter-sort-paginate)
[![Code Climate](https://codeclimate.com/github/scull7/filter-sort-paginate/badges/gpa.svg)](https://codeclimate.com/github/scull7/filter-sort-paginate)

filter-sort-paginate
====================

This is a simple filter sort paginate module designed to work 
with expressJS like frameworks.

usage
-----

```javascript

var fsp     = require('filter-sort-paginate'),
    express = require('express'),
    mysql   = require('mysql'),
    app     = express()
;

app.use(function (req, res, next) {
  req.mysql = ... //get mysql connection
});

app.get('/', fsp('table_name'))

```

The response will be an object that has the following structure:

```javascript
{
  items: [ { name: 'value' }, ... ],
  total: 10, // total number of items produced by the query.
  field_data: [ { /* column data from mysql */ ... ],
  repository: 'table_name', // name of the current table.
  fields: [ /* any currently specified fields */ ],
  sorts: [ /* any currently specified sort fields */ ],
  filters: [ /* any currently specified filters */ ],
  limit: 100, // 100 is the default limit
  page: 1, // page is one based
}
```

Given the following request URL

`/?filter=test:is:something|this:gt:that&sort=+test|-that&page=2&limit=25`

With the following set up.

```javascript
  app.get('/', fsp('table_name', [ 'test', { column: 'this', alias: 'me' }, 'that' ]));
```

The following response will be generated

```javascript
{
  items: [ { test: 'something', this: 'then', that: 'this' }, ... ],
  total: 10, // total number of items produced by the query.
  field_data: [ { /* column data from mysql */ ...} ],
  repository: 'table_name', // name of the current table.
  fields: [
    { column: 'test', alias: null },
    { column: 'this', alias: 'me' },
    { column: 'that', alias: null }
  ],
  sorts: [
    { column: 'test', direction: '+' },
    { column: 'that', direction: '-' }
  ],
  filters: [
    { column: 'test', action: 'is', value: 'something' },
    { column: 'this', action: 'gt', value: 'that' }
  ],
  limit: 25, // 100 is the default limit
  page: 2, // page is one based
}
```

To Do
-----

* Fix exceptions in MySQL driver not being caught.
* Add concept of defaults to the options array.  
  These will be default filters, sorts, etc...

---
_Source: https://npm.io/package/filter-sort-paginate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
