Browse Source

fix(nocodb): condition like logic

pull/5106/head
Wing-Kam Wong 2 years ago
parent
commit
0cf9f4d4e4
  1. 11
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/conditionV2.ts

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

@ -284,21 +284,28 @@ const parseConditionV2 = async (
});
break;
case 'like':
if (!val) {
// val is empty -> all values including empty strings but NULL
qb.where(field, '');
qb.orWhereNotNull(field);
} else {
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%');
} else {
val = val.startsWith('%') || val.endsWith('%') ? val : `%${val}%`;
val =
val.startsWith('%') || val.endsWith('%') ? val : `%${val}%`;
}
if (qb?.client?.config?.client === 'pg') {
qb = qb.whereRaw('??::text ilike ?', [field, val]);
} else {
qb = qb.where(field, 'like', val);
}
}
break;
case 'nlike':
if (!val) {
// val is empty -> include all values but empty strings
// val is empty -> all values including NULL but empty strings
qb.whereNot(field, '');
qb.orWhereNull(field);
} else {

Loading…
Cancel
Save