Browse Source

refactor(nocodb): setUtcTimezoneForPg

pull/5601/head
Wing-Kam Wong 2 years ago
parent
commit
873e52b235
  1. 32
      packages/nocodb-nest/src/db/BaseModelSqlv2.ts

32
packages/nocodb-nest/src/db/BaseModelSqlv2.ts

@ -15,10 +15,6 @@ import ejs from 'ejs';
import Validator from 'validator'; import Validator from 'validator';
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
import DOMPurify from 'isomorphic-dompurify'; import DOMPurify from 'isomorphic-dompurify';
const GROUP_COL = '__nc_group_id';
const nanoidv2 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 14);
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { NcError } from '../helpers/catchError'; import { NcError } from '../helpers/catchError';
import getAst from '../helpers/getAst'; import getAst from '../helpers/getAst';
@ -29,6 +25,7 @@ import {
} from '../helpers/webhookHelpers'; } from '../helpers/webhookHelpers';
import { import {
Audit, Audit,
Base,
Column, Column,
Filter, Filter,
FormView, FormView,
@ -67,6 +64,10 @@ import type {
import type { Knex } from 'knex'; import type { Knex } from 'knex';
import type { SortType } from 'nocodb-sdk'; import type { SortType } from 'nocodb-sdk';
const GROUP_COL = '__nc_group_id';
const nanoidv2 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 14);
export async function getViewAndModelByAliasOrId(param: { export async function getViewAndModelByAliasOrId(param: {
projectName: string; projectName: string;
tableName: string; tableName: string;
@ -1755,9 +1756,7 @@ class BaseModelSqlv2 {
let response; let response;
// const driver = trx ? trx : this.dbDriver; // const driver = trx ? trx : this.dbDriver;
if (this.isPg) { await this.setUtcTimezoneForPg();
await this.dbDriver.raw(`SET TIME ZONE 'UTC'`);
}
const query = this.dbDriver(this.tnPath).insert(insertObj); const query = this.dbDriver(this.tnPath).insert(insertObj);
if ((this.isPg || this.isMssql) && this.model.primaryKey) { if ((this.isPg || this.isMssql) && this.model.primaryKey) {
@ -1893,9 +1892,7 @@ class BaseModelSqlv2 {
const prevData = await this.readByPk(id); const prevData = await this.readByPk(id);
if (this.isPg) { await this.setUtcTimezoneForPg();
await this.dbDriver.raw(`SET TIME ZONE 'UTC'`);
}
const query = this.dbDriver(this.tnPath) const query = this.dbDriver(this.tnPath)
.update(updateObj) .update(updateObj)
@ -2130,9 +2127,7 @@ class BaseModelSqlv2 {
// refer : https://www.sqlite.org/limits.html // refer : https://www.sqlite.org/limits.html
const chunkSize = this.isSqlite ? 10 : _chunkSize; const chunkSize = this.isSqlite ? 10 : _chunkSize;
if (this.isPg) { await this.setUtcTimezoneForPg();
await this.dbDriver.raw(`SET TIME ZONE 'UTC'`);
}
const response = const response =
this.isPg || this.isMssql this.isPg || this.isMssql
@ -2180,9 +2175,7 @@ class BaseModelSqlv2 {
updatePkValues.push(pkValues); updatePkValues.push(pkValues);
} }
if (this.isPg) { await this.setUtcTimezoneForPg();
await this.dbDriver.raw(`SET TIME ZONE 'UTC'`);
}
transaction = await this.dbDriver.transaction(); transaction = await this.dbDriver.transaction();
@ -3176,6 +3169,13 @@ class BaseModelSqlv2 {
} }
return data; return data;
} }
private async setUtcTimezoneForPg() {
const base = await Base.get(this.model.base_id);
if (this.isPg && base.is_meta) {
await this.dbDriver.raw(`SET TIME ZONE 'UTC'`);
}
}
} }
function extractSortsObject( function extractSortsObject(

Loading…
Cancel
Save