Browse Source

feat: `CreateTime` or `LastModifiedTime` - select query - singleQuery

pull/7304/head
Pranav C 12 months ago
parent
commit
d000252ac1
  1. 20
      packages/nocodb/src/db/BaseModelSqlv2.ts

20
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -2126,7 +2126,8 @@ class BaseModelSqlv2 {
switch (column.uidt) {
case UITypes.CreateTime:
case UITypes.LastModifiedTime:
case UITypes.DateTime: {
case UITypes.DateTime:
{
const columnName = getColumnName(column);
if (this.isMySQL) {
// MySQL stores timestamp in UTC but display in timezone
@ -2137,9 +2138,9 @@ class BaseModelSqlv2 {
// the value 2023-01-01 10:00:00 (UTC) would display as 2023-01-01 18:00:00 (UTC+8)
// our existing logic is based on UTC, during the query, we need to take the UTC value
// hence, we use CONVERT_TZ to convert back to UTC value
res[sanitize(column.id || column.column_name)] = this.dbDriver.raw(
res[sanitize(column.id || columnName)] = this.dbDriver.raw(
`CONVERT_TZ(??, @@GLOBAL.time_zone, '+00:00')`,
[`${sanitize(alias || this.tnPath)}.${column.column_name}`],
[`${sanitize(alias || this.tnPath)}.${columnName}`],
);
break;
} else if (this.isPg) {
@ -2150,10 +2151,10 @@ class BaseModelSqlv2 {
column.dt !== 'timestamp with time zone' &&
column.dt !== 'timestamptz'
) {
res[sanitize(column.id || column.column_name)] = this.dbDriver
res[sanitize(column.id || columnName)] = this.dbDriver
.raw(
`?? AT TIME ZONE CURRENT_SETTING('timezone') AT TIME ZONE 'UTC'`,
[`${sanitize(alias || this.tnPath)}.${column.column_name}`],
[`${sanitize(alias || this.tnPath)}.${columnName}`],
)
.wrap('(', ')');
break;
@ -2163,16 +2164,15 @@ class BaseModelSqlv2 {
// convert to database timezone,
// then convert to UTC
if (column.dt !== 'datetimeoffset') {
res[sanitize(column.id || column.column_name)] =
this.dbDriver.raw(
res[sanitize(column.id || columnName)] = this.dbDriver.raw(
`CONVERT(DATETIMEOFFSET, ?? AT TIME ZONE 'UTC')`,
[`${sanitize(alias || this.tnPath)}.${column.column_name}`],
[`${sanitize(alias || this.tnPath)}.${columnName}`],
);
break;
}
}
res[sanitize(column.id || column.column_name)] = sanitize(
`${alias || this.tnPath}.${column.column_name}`,
res[sanitize(column.id || columnName)] = sanitize(
`${alias || this.tnPath}.${columnName}`,
);
}
break;

Loading…
Cancel
Save