egg-mysql-paginator
v1.0.1
Published
MySQL paginator plugin for egg
Downloads
185
Readme
egg-mysql-paginator
Paginator for egg-mysql
Install
$ npm i egg-mysql-paginator --save
Usage
// {app_root}/config/plugin.js
exports.mysqlPaginator = {
enable: true,
package: 'egg-mysql-paginator',
};
Example
// query
const results = await app.mysqlPaginator.query('posts',{
where: { status: 'draft' },
orders: [['created_at','desc'], ['id','desc']],
page: 1,
size: 10
});
// result
{
pagination: {
total: 21,
size: 10,
currentPage: 1,
lastPage: 3,
from: 0,
to: 10
},
data: [...]
}
Fuzzy query
const results = await app.mysqlPaginator.query('posts',{
where: 'WHERE name LIKE %name%',
orders: [['created_at','desc'], ['id','desc']],
page: 1,
size: 10
});
Customized order by
const results = await app.mysqlPaginator.query('posts',{
where: 'WHERE name LIKE %name%',
orders: 'rank+',
page: 1,
size: 10
});