knex-pageinate

علی ذوالفقار
1402/01/22 10:34:45 (191)
const { attachPaginate } = require('knex-paginate');
var db = require('knex')({
    client: 'mysql',
    connection: connectionConfig ,
    pool: { min: 0, max: 50 }
});
// the next line add pagination to kenex 
attachPaginate();


data = await db('my_table')
    //.select(fields)
    .where(`${req.query.filterBy}` , 'like' , `%${req.query.filter}%`)
    .orderBy('create_date','desc')
    .paginate( { perPage: 10 , currentPage: 1 , isLengthAware : true });
    // isLengthAware  cause knex return total page count in response 
Back