Browse Source

Merge pull request #2204 from nocodb/fix/formula-filter

fix: formula filter
pull/2217/head
աɨռɢӄաօռɢ 3 years ago committed by GitHub
parent
commit
09b9d26098
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      packages/nocodb/src/lib/dataMapper/lib/sql/conditionV2.ts

27
packages/nocodb/src/lib/dataMapper/lib/sql/conditionV2.ts

@ -203,12 +203,13 @@ const parseConditionV2 = async (
filter.comparison_op === 'notempty'
)
filter.value = '';
const field = customWhereClause
let field = customWhereClause
? filter.value
: alias
? `${alias}.${column.column_name}`
: column.column_name;
const val = customWhereClause ? customWhereClause : filter.value;
let val = customWhereClause ? customWhereClause : filter.value;
return qb => {
switch (filter.comparison_op) {
case 'eq':
@ -218,17 +219,29 @@ const parseConditionV2 = async (
qb = qb.whereNot(field, val);
break;
case 'like':
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%')
} else {
val = `%${val}%`;
}
qb = qb.where(
field,
qb?.client?.config?.client === 'pg' ? 'ilike' : 'like',
`%${val}%`
val
);
break;
case 'nlike':
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%')
} else {
val = `%${val}%`;
}
qb = qb.whereNot(
field,
qb?.client?.config?.client === 'pg' ? 'ilike' : 'like',
`%${val}%`
val
);
break;
case 'gt':
@ -273,9 +286,15 @@ const parseConditionV2 = async (
break;
case 'empty':
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
}
qb = qb.where(field, val);
break;
case 'notempty':
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
}
qb = qb.whereNot(field, val);
break;
case 'null':

Loading…
Cancel
Save