Browse Source

fix(api): in not like result include null values as well

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4922/head
Pranav C 2 years ago
parent
commit
b5068334b5
  1. 75
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

75
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

@ -303,50 +303,55 @@ const parseConditionV2 = async (
} else { } else {
val = val.startsWith('%') || val.endsWith('%') ? val : `%${val}%`; val = val.startsWith('%') || val.endsWith('%') ? val : `%${val}%`;
} }
if (qb?.client?.config?.client === 'pg') { qb.where((nestedQb) => {
qb = qb.whereRaw('??::text not ilike ?', [field, val]); if (qb?.client?.config?.client === 'pg') {
} else { nestedQb.whereRaw('??::text not ilike ?', [field, val]);
qb = qb.whereNot(field, 'like', val); } else {
} nestedQb.whereNot(field, 'like', val);
}
nestedQb.orWhereNull(field);
});
break; break;
case 'allof': case 'allof':
case 'anyof': case 'anyof':
case 'nallof': case 'nallof':
case 'nanyof': case 'nanyof':
// Condition for filter, without negation {
const condition = (builder: Knex.QueryBuilder) => { // Condition for filter, without negation
const items = val.split(',').map((item) => item.trim()); const condition = (builder: Knex.QueryBuilder) => {
for (let i = 0; i < items.length; i++) { const items = val.split(',').map((item) => item.trim());
let sql; for (let i = 0; i < items.length; i++) {
const bindings = [field, `%,${items[i]},%`]; let sql;
if (qb?.client?.config?.client === 'pg') { const bindings = [field, `%,${items[i]},%`];
sql = "(',' || ??::text || ',') ilike ?"; if (qb?.client?.config?.client === 'pg') {
} else if (qb?.client?.config?.client === 'sqlite3') { sql = "(',' || ??::text || ',') ilike ?";
sql = "(',' || ?? || ',') like ?"; } else if (qb?.client?.config?.client === 'sqlite3') {
} else { sql = "(',' || ?? || ',') like ?";
sql = "CONCAT(',', ??, ',') like ?"; } else {
} sql = "CONCAT(',', ??, ',') like ?";
if (i === 0) { }
builder = builder.whereRaw(sql, bindings); if (i === 0) {
} else { builder = builder.whereRaw(sql, bindings);
if (
filter.comparison_op === 'allof' ||
filter.comparison_op === 'nallof'
) {
builder = builder.andWhereRaw(sql, bindings);
} else { } else {
builder = builder.orWhereRaw(sql, bindings); if (
filter.comparison_op === 'allof' ||
filter.comparison_op === 'nallof'
) {
builder = builder.andWhereRaw(sql, bindings);
} else {
builder = builder.orWhereRaw(sql, bindings);
}
} }
} }
};
if (
filter.comparison_op === 'allof' ||
filter.comparison_op === 'anyof'
) {
qb = qb.where(condition);
} else {
qb = qb.whereNot(condition).orWhereNull(field);
} }
};
if (
filter.comparison_op === 'allof' ||
filter.comparison_op === 'anyof'
) {
qb = qb.where(condition);
} else {
qb = qb.whereNot(condition).orWhereNull(field);
} }
break; break;
case 'gt': case 'gt':

Loading…
Cancel
Save