Browse Source

refactor(nocodb): remove parseDateOrDateTimeCondition

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

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

@ -35,15 +35,6 @@ function getLogicalOpMethod(filter: Filter) {
}
}
function parseDateOrDateTimeCondition(
qb: Knex.QueryBuilder,
op: '>' | '<' | '>=' | '<=' | '=' | '!=',
val: any
) {
// TODO:
console.log(qb, op, val);
}
const parseConditionV2 = async (
_filter: Filter | Filter[],
knex: XKnex,
@ -280,10 +271,14 @@ const parseConditionV2 = async (
return (qb: Knex.QueryBuilder) => {
let [field, val] = [_field, _val];
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt) && !val) {
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) {
if (!val) {
// for date & datetime, val cannot be empty for all filters
return;
}
// handle sub operation
// TODO:
}
if (isNumericCol(column.uidt) && typeof val === 'string') {
// convert to number
@ -292,9 +287,6 @@ const parseConditionV2 = async (
switch (filter.comparison_op) {
case 'eq':
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) {
parseDateOrDateTimeCondition(qb, '=', val);
} else {
if (qb?.client?.config?.client === 'mysql2') {
if (
[
@ -319,13 +311,9 @@ const parseConditionV2 = async (
// unset rating is considered as NULL
qb = qb.orWhereNull(field);
}
}
break;
case 'neq':
case 'not':
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) {
parseDateOrDateTimeCondition(qb, '!=', val);
} else {
if (qb?.client?.config?.client === 'mysql2') {
if (
[
@ -365,7 +353,6 @@ const parseConditionV2 = async (
.orWhereNull(customWhereClause ? _val : _field);
});
}
}
break;
case 'like':
if (!val) {
@ -474,9 +461,6 @@ const parseConditionV2 = async (
break;
case 'gt':
const gt_op = customWhereClause ? '<' : '>';
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) {
parseDateOrDateTimeCondition(qb, gt_op, val);
} else {
qb = qb.where(field, gt_op, val);
if (column.uidt === UITypes.Rating) {
// unset rating is considered as NULL
@ -484,14 +468,10 @@ const parseConditionV2 = async (
qb = qb.orWhereNull(field);
}
}
}
break;
case 'ge':
case 'gte':
const ge_op = customWhereClause ? '<=' : '>=';
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) {
parseDateOrDateTimeCondition(qb, ge_op, val);
} else {
qb = qb.where(field, ge_op, val);
if (column.uidt === UITypes.Rating) {
// unset rating is considered as NULL
@ -499,13 +479,9 @@ const parseConditionV2 = async (
qb = qb.orWhereNull(field);
}
}
}
break;
case 'lt':
const lt_op = customWhereClause ? '>' : '<';
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) {
parseDateOrDateTimeCondition(qb, lt_op, val);
} else {
qb = qb.where(field, lt_op, val);
if (column.uidt === UITypes.Rating) {
// unset number is considered as NULL
@ -513,14 +489,10 @@ const parseConditionV2 = async (
qb = qb.orWhereNull(field);
}
}
}
break;
case 'le':
case 'lte':
const le_op = customWhereClause ? '>=' : '<=';
if ([UITypes.Date, UITypes.DateTime].includes(column.uidt)) {
parseDateOrDateTimeCondition(qb, le_op, val);
} else {
qb = qb.where(field, le_op, val);
if (column.uidt === UITypes.Rating) {
// unset number is considered as NULL
@ -528,7 +500,6 @@ const parseConditionV2 = async (
qb = qb.orWhereNull(field);
}
}
}
break;
case 'in':
qb = qb.whereIn(

Loading…
Cancel
Save