
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
url-db-paging
Advanced tools
A library to help creating paging results through URLs.
Do you want another provider? Please open an issue or even better send us a pull request.
query
: request query stringdefaultSortField
: default primary sort fieldidField
: data's id fieldroot
: base urllimit
: limit results per pagequeryBuilderType
: query builder type (mongoose, solr or knex)var express = require('express'),
Paging = require('url-db-paging'),
User = require('./models/user');
var app = express();
app.get('/', function(req, res, next){
var userQuery = User.find();
var limit = parseInt(query.limit, 10) || 20;
var paging = new Paging({
query: req.query, // query string
defaultSortField: '-created', // default sort field
defaultSortField: {column: '-created', json: 'createdAt'}, // define the column to sort and the JSON value of createdAt
idField: '_id', // data's id field
idField: {column: '_id', json: 'id'}, // define the id column in database and
root: 'http://service/users', // base url
limit: limit, // limit per page
queryBuilderType: 'mongoose' // query builder type
});
//OR: When your JSON data it's different than the column/property in yours database you can define those changes like:
var paging = new Paging({
query: req.query, // query string
defaultSortField: {column: '-created', json: 'createdAt'} // define the column to sort and the JSON value of createdAt
idField: {column: '_id', json: 'id'} // define the id column in database and
root: 'http://service/users', // base url
limit: limit, // limit per page
queryBuilderType: 'mongoose' // query builder type
});
// add sort db query
paging.addSortDbQuery(userQuery);
userQuery
.sort(paging.getSortQuery()) // sort using paging
.limit(paging.getLimitQuery()) // limit using paging
.exec()
.then(result, next);
function result(users) {
var data = paging.buildPagingResult(users); // add paging into data result
return res.status(200).send(data);
}
});
module.exports = app;
{
list:[
{ ... },
{ ... },
{ ... }
],
_links: {
previous: {
href: "http://service/users?limit=5&sort=-created&offset_date=2014-07-31T12%3A05%3A24.865Z&offset_id=53da3104d14bdb2500cc203d&dir=backward"
},
next: {
href: "http://service/users?limit=5&sort=-created&offset_date=2014-07-31T12%3A05%3A24.854Z&offset_id=53da3104d14bdb2500cc2035&dir=forward"
}
}
}
It is required to use editorconfig and please write and run specs before pushing any changes:
npm test
FAQs
A library to help creating paging results through URLs
The npm package url-db-paging receives a total of 5 weekly downloads. As such, url-db-paging popularity was classified as not popular.
We found that url-db-paging demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.