surveilr / www.surveilr.com

Resource Surveillance & Integration Engine (`surveilr`) Public Facing Omnibus Monorepo
https://www.surveilr.com
MIT License
0 stars 11 forks source link

feat: pagination count add where condition #20 #123

Closed jobyjames1 closed 1 week ago

jobyjames1 commented 1 week ago

This PR introduces the capability to apply a WHERE condition in the row count calculation of the pagination function. This enhancement allows for more refined data retrieval by filtering records based on specified conditions, improving the flexibility and efficiency of pagination when dealing with large datasets.

const pagination = this.pagination({
  tableOrViewName: 'view_name', 
  whereSQL: ["condition_field"], 
});

Key Changes in pagination Function

const countSQL = config.countSQL
  ? config.countSQL
  : this.SQL`SELECT COUNT(*) FROM ${config.tableOrViewName}${
    config.whereSQL && config.whereSQL.length > 0
      ? ` WHERE ${
        config.whereSQL.map((qp) => `${n(qp)} =${$(qp)}`).join(" AND ")
      }`
      : ``
  }`;