Browse Source

fix(nocodb): sqlite, mysql2 lt, lte, gt, gte fix

pull/7611/head
DarkPhoenix2704 6 months ago
parent
commit
b6876d1458
  1. 2
      packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue
  2. 84
      packages/nocodb/src/db/conditionV2.ts

2
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-1 !border-brand-500 bg-gray-50': hour.isSame(selectedTime, 'hour'),
'!border-l-0': date[0].day() === selectedDateRange.start?.day(), '!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=" @click="
() => { () => {
selectedTime = hour selectedTime = hour

84
packages/nocodb/src/db/conditionV2.ts

@ -903,10 +903,29 @@ const parseConditionV2 = async (
// then we need to convert the value to timestamptz before comparing // then we need to convert the value to timestamptz before comparing
if ( if (
column.uidt === UITypes.DateTime && column.uidt === UITypes.DateTime &&
qb.client.config.client === 'pg' &&
val.match(/[+-]\d{2}:\d{2}$/) val.match(/[+-]\d{2}:\d{2}$/)
) { ) {
if (qb.client.config.client === 'pg') {
qb.where(field, gt_op, knex.raw('?::timestamptz', [val])); 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 { } else {
qb = qb.where(field, gt_op, val); qb = qb.where(field, gt_op, val);
if (column.uidt === UITypes.Rating) { if (column.uidt === UITypes.Rating) {
@ -926,10 +945,29 @@ const parseConditionV2 = async (
// then we need to convert the value to timestamptz before comparing // then we need to convert the value to timestamptz before comparing
if ( if (
column.uidt === UITypes.DateTime && column.uidt === UITypes.DateTime &&
qb.client.config.client === 'pg' &&
val.match(/[+-]\d{2}:\d{2}$/) val.match(/[+-]\d{2}:\d{2}$/)
) { ) {
if (qb.client.config.client === 'pg') {
qb.where(field, ge_op, knex.raw('?::timestamptz', [val])); 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 { } else {
qb = qb.where(field, ge_op, val); qb = qb.where(field, ge_op, val);
if (column.uidt === UITypes.Rating) { if (column.uidt === UITypes.Rating) {
@ -948,10 +986,29 @@ const parseConditionV2 = async (
// then we need to convert the value to timestamptz before comparing // then we need to convert the value to timestamptz before comparing
if ( if (
column.uidt === UITypes.DateTime && column.uidt === UITypes.DateTime &&
qb.client.config.client === 'pg' &&
val.match(/[+-]\d{2}:\d{2}$/) val.match(/[+-]\d{2}:\d{2}$/)
) { ) {
if (qb.client.config.client === 'pg') {
qb.where(field, lt_op, knex.raw('?::timestamptz', [val])); 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 { } else {
qb = qb.where(field, lt_op, val); qb = qb.where(field, lt_op, val);
if (column.uidt === UITypes.Rating) { if (column.uidt === UITypes.Rating) {
@ -972,10 +1029,29 @@ const parseConditionV2 = async (
// then we need to convert the value to timestamptz before comparing // then we need to convert the value to timestamptz before comparing
if ( if (
column.uidt === UITypes.DateTime && column.uidt === UITypes.DateTime &&
qb.client.config.client === 'pg' &&
val.match(/[+-]\d{2}:\d{2}$/) val.match(/[+-]\d{2}:\d{2}$/)
) { ) {
if (qb.client.config.client === 'pg') {
qb.where(field, le_op, knex.raw('?::timestamptz', [val])); 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 { } else {
qb = qb.where(field, le_op, val); qb = qb.where(field, le_op, val);
if (column.uidt === UITypes.Rating) { if (column.uidt === UITypes.Rating) {

Loading…
Cancel
Save