From b6876d1458912aeee5732f41e3d33abbebd0226a Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Tue, 20 Feb 2024 07:16:19 +0000 Subject: [PATCH] fix(nocodb): sqlite, mysql2 lt, lte, gt, gte fix --- .../calendar/WeekView/DateTimeField.vue | 2 +- packages/nocodb/src/db/conditionV2.ts | 92 +++++++++++++++++-- 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue index 49f48ff065..134dcfd136 100644 --- a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue @@ -747,7 +747,7 @@ const viewMore = (hour: dayjs.Dayjs) => { 'border-1 !border-brand-500 bg-gray-50': hour.isSame(selectedTime, 'hour'), '!border-l-0': date[0].day() === selectedDateRange.start?.day(), }" - class="text-center relative h-20 text-sm text-gray-500 w-full py-1 border-gray-200 first:border-l-none border-1 border-r-gray-50 border-t-gray-50" + class="text-center relative h-20 text-sm text-gray-500 w-full hover:bg-gray-50 py-1 border-gray-200 first:border-l-none border-1 border-r-gray-50 border-t-gray-50" @click=" () => { selectedTime = hour diff --git a/packages/nocodb/src/db/conditionV2.ts b/packages/nocodb/src/db/conditionV2.ts index 926b00afd7..9613310c07 100644 --- a/packages/nocodb/src/db/conditionV2.ts +++ b/packages/nocodb/src/db/conditionV2.ts @@ -903,10 +903,29 @@ const parseConditionV2 = async ( // then we need to convert the value to timestamptz before comparing if ( column.uidt === UITypes.DateTime && - qb.client.config.client === 'pg' && val.match(/[+-]\d{2}:\d{2}$/) ) { - qb.where(field, gt_op, knex.raw('?::timestamptz', [val])); + if (qb.client.config.client === 'pg') { + qb.where(field, gt_op, knex.raw('?::timestamptz', [val])); + } else if (qb.client.config.client === 'sqlite3') { + qb.where( + field, + gt_op, + knex.raw('datetime(?)', [ + dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss'), + ]), + ); + } else if (qb.client.config.client === 'mysql2') { + qb.where( + field, + gt_op, + knex.raw(`CONVERT_TZ(?, '+00:00', @@GLOBAL.time_zone)`, [ + dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss'), + ]), + ); + } else { + qb.where(field, gt_op, val); + } } else { qb = qb.where(field, gt_op, val); if (column.uidt === UITypes.Rating) { @@ -926,10 +945,29 @@ const parseConditionV2 = async ( // then we need to convert the value to timestamptz before comparing if ( column.uidt === UITypes.DateTime && - qb.client.config.client === 'pg' && val.match(/[+-]\d{2}:\d{2}$/) ) { - qb.where(field, ge_op, knex.raw('?::timestamptz', [val])); + if (qb.client.config.client === 'pg') { + qb.where(field, ge_op, knex.raw('?::timestamptz', [val])); + } else if (qb.client.config.client === 'sqlite3') { + qb.where( + field, + ge_op, + knex.raw('datetime(?)', [ + dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss'), + ]), + ); + } else if (qb.client.config.client === 'mysql2') { + qb.where( + field, + ge_op, + knex.raw(`CONVERT_TZ(?, '+00:00', @@GLOBAL.time_zone)`, [ + dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss'), + ]), + ); + } else { + qb.where(field, ge_op, val); + } } else { qb = qb.where(field, ge_op, val); if (column.uidt === UITypes.Rating) { @@ -948,10 +986,29 @@ const parseConditionV2 = async ( // then we need to convert the value to timestamptz before comparing if ( column.uidt === UITypes.DateTime && - qb.client.config.client === 'pg' && val.match(/[+-]\d{2}:\d{2}$/) ) { - qb.where(field, lt_op, knex.raw('?::timestamptz', [val])); + if (qb.client.config.client === 'pg') { + qb.where(field, lt_op, knex.raw('?::timestamptz', [val])); + } else if (qb.client.config.client === 'sqlite3') { + qb.where( + field, + lt_op, + knex.raw('datetime(?)', [ + dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss'), + ]), + ); + } else if (qb.client.config.client === 'mysql2') { + qb.where( + field, + lt_op, + knex.raw(`CONVERT_TZ(?, '+00:00', @@GLOBAL.time_zone)`, [ + dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss'), + ]), + ); + } else { + qb.where(field, lt_op, val); + } } else { qb = qb.where(field, lt_op, val); if (column.uidt === UITypes.Rating) { @@ -972,10 +1029,29 @@ const parseConditionV2 = async ( // then we need to convert the value to timestamptz before comparing if ( column.uidt === UITypes.DateTime && - qb.client.config.client === 'pg' && val.match(/[+-]\d{2}:\d{2}$/) ) { - qb.where(field, le_op, knex.raw('?::timestamptz', [val])); + if (qb.client.config.client === 'pg') { + qb.where(field, le_op, knex.raw('?::timestamptz', [val])); + } else if (qb.client.config.client === 'sqlite3') { + qb.where( + field, + le_op, + knex.raw('datetime(?)', [ + dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss'), + ]), + ); + } else if (qb.client.config.client === 'mysql2') { + qb.where( + field, + le_op, + knex.raw(`CONVERT_TZ(?, '+00:00', @@GLOBAL.time_zone)`, [ + dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss'), + ]), + ); + } else { + qb.where(field, le_op, val); + } } else { qb = qb.where(field, le_op, val); if (column.uidt === UITypes.Rating) {