Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PagiHelp {
returnString +=
this.tupleCreator(schemaObject, replacements, asItIs) + " AND ";
} else {
let subString = "( ";
let subString = "(";
for (let subObject of schemaObject) {
subString += this.genSchema(subObject, replacements, asItIs) + " OR ";
}
Expand Down Expand Up @@ -184,35 +184,32 @@ class PagiHelp {
"`" +
joinQuery;

let totalCountQuery =
let totalCountQuery =
"SELECT COUNT(*) AS countValue " +
" FROM `" +
tableName +
"`" +
joinQuery;

let replacements = [];
let whereQuery = " WHERE ";
let whereQuery = "";

if (additionalWhereConditions.length > 0) {
whereQuery += this.genSchema(additionalWhereConditions, replacements, true) + " AND ";
whereQuery += (whereQuery === "" ? " WHERE " : " AND ") + this.genSchema(additionalWhereConditions, replacements, true);
}
if (filterConditions.length > 0) {
whereQuery += this.genSchema(filterConditions, replacements, false) + " AND ";
whereQuery += (whereQuery === "" ? " WHERE " : " AND ") + this.genSchema(filterConditions, replacements, false);
}

if(searchColumnList && searchColumnList.length>0 && paginationObject.search !== "") {
whereQuery = whereQuery + "( ";
if(searchColumnList && searchColumnList.length > 0 && paginationObject.search !== "") {
whereQuery += (whereQuery === "" ? " WHERE " : " AND ") + "(";
for (let column of searchColumnList) {
whereQuery = whereQuery + column + " LIKE ? OR ";
replacements.push(`%${paginationObject.search}%`);
whereQuery += column + " LIKE ? OR ";
replacements.push(`%${paginationObject.search}%`);
}
whereQuery = rtrim(whereQuery, "OR ");
whereQuery = whereQuery + " )";
} else {
whereQuery = rtrim(whereQuery, "AND ");
whereQuery = whereQuery.replace(/\s*(AND|OR)\s*$/i, "");
whereQuery += ")";
}


query = query + whereQuery;
countQuery = countQuery + whereQuery;
Expand Down