Browse Source

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

fix: formula filter
pull/2217/head
աɨռɢӄաօռɢ 2 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.comparison_op === 'notempty'
) )
filter.value = ''; filter.value = '';
const field = customWhereClause let field = customWhereClause
? filter.value ? filter.value
: alias : alias
? `${alias}.${column.column_name}` ? `${alias}.${column.column_name}`
: column.column_name; : column.column_name;
const val = customWhereClause ? customWhereClause : filter.value; let val = customWhereClause ? customWhereClause : filter.value;
return qb => { return qb => {
switch (filter.comparison_op) { switch (filter.comparison_op) {
case 'eq': case 'eq':
@ -218,17 +219,29 @@ const parseConditionV2 = async (
qb = qb.whereNot(field, val); qb = qb.whereNot(field, val);
break; break;
case 'like': case 'like':
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%')
} else {
val = `%${val}%`;
}
qb = qb.where( qb = qb.where(
field, field,
qb?.client?.config?.client === 'pg' ? 'ilike' : 'like', qb?.client?.config?.client === 'pg' ? 'ilike' : 'like',
`%${val}%` val
); );
break; break;
case 'nlike': case 'nlike':
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
val = `%${val}%`.replace(/^%'([\s\S]*)'%$/, '%$1%')
} else {
val = `%${val}%`;
}
qb = qb.whereNot( qb = qb.whereNot(
field, field,
qb?.client?.config?.client === 'pg' ? 'ilike' : 'like', qb?.client?.config?.client === 'pg' ? 'ilike' : 'like',
`%${val}%` val
); );
break; break;
case 'gt': case 'gt':
@ -273,9 +286,15 @@ const parseConditionV2 = async (
break; break;
case 'empty': case 'empty':
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
}
qb = qb.where(field, val); qb = qb.where(field, val);
break; break;
case 'notempty': case 'notempty':
if (column.uidt === UITypes.Formula) {
[field, val] = [val, field];
}
qb = qb.whereNot(field, val); qb = qb.whereNot(field, val);
break; break;
case 'null': case 'null':

Loading…
Cancel
Save