https://github.com/scull7/filter-sort-paginate
This is a simple filter sort paginate module designed to work with expressJS like
https://github.com/scull7/filter-sort-paginate
Last synced: about 1 year ago
JSON representation
This is a simple filter sort paginate module designed to work with expressJS like
- Host: GitHub
- URL: https://github.com/scull7/filter-sort-paginate
- Owner: scull7
- License: gpl-2.0
- Created: 2014-08-31T04:34:10.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-09-15T17:43:15.000Z (almost 12 years ago)
- Last Synced: 2025-06-24T09:48:50.039Z (about 1 year ago)
- Language: CoffeeScript
- Size: 328 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/scull7/filter-sort-paginate)
[](https://coveralls.io/r/scull7/filter-sort-paginate)
[](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...