From 244873ec53eb59f893b8d1c5b314abfa8a54bb93 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 19 Aug 2024 07:55:03 +0000 Subject: [PATCH] refactor: function name --- packages/nc-gui/components/smartsheet/Cell.vue | 4 ++-- .../smartsheet/column/DefaultValue.vue | 4 ++-- .../nocodb-sdk/src/lib/sqlUi/DatabricksUi.ts | 3 ++- packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts | 3 ++- packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts | 18 ++++++++++++++++-- packages/nocodb-sdk/src/lib/sqlUi/OracleUi.ts | 4 ++-- packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts | 8 ++++++-- .../nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts | 3 ++- packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts | 3 ++- 9 files changed, 36 insertions(+), 14 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Cell.vue b/packages/nc-gui/components/smartsheet/Cell.vue index d17ee293e6..82c1252a91 100644 --- a/packages/nc-gui/components/smartsheet/Cell.vue +++ b/packages/nc-gui/components/smartsheet/Cell.vue @@ -128,12 +128,12 @@ const showCurrentDateOption = computed(() => { return ( isEditColumnMenu.value && (isDate(column.value, abstractType.value) || isDateTime(column.value, abstractType.value)) && - sqlUi.value?.getNowDefaultVal?.() + sqlUi.value?.getCurrentDateDefault?.(column.value) ) }) const currentDate = () => { - vModel.value = sqlUi.value?.getNowDefaultVal?.() + vModel.value = sqlUi.value?.getCurrentDateDefault?.(column.value) } diff --git a/packages/nc-gui/components/smartsheet/column/DefaultValue.vue b/packages/nc-gui/components/smartsheet/column/DefaultValue.vue index 0b14984403..86cb23fefd 100644 --- a/packages/nc-gui/components/smartsheet/column/DefaultValue.vue +++ b/packages/nc-gui/components/smartsheet/column/DefaultValue.vue @@ -52,11 +52,11 @@ const sqlUi = computed(() => ) const showCurrentDateOption = computed(() => { - return [UITypes.Date, UITypes.DateTime].includes(vModel.value?.uidt) && sqlUi.value?.getNowDefaultVal?.() + return [UITypes.Date, UITypes.DateTime].includes(vModel.value?.uidt) && sqlUi.value?.getCurrentDateDefault?.(vModel.value) }) const isCurrentDate = computed(() => { - return showCurrentDateOption.value && cdfValue.value?.toUpperCase?.() === sqlUi.value?.getNowDefaultVal?.() + return showCurrentDateOption.value && cdfValue.value?.toUpperCase?.() === sqlUi.value?.getCurrentDateDefault?.(vModel.value) }) diff --git a/packages/nocodb-sdk/src/lib/sqlUi/DatabricksUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/DatabricksUi.ts index 2975ac7828..1927f1b1cf 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/DatabricksUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/DatabricksUi.ts @@ -1,5 +1,6 @@ import UITypes from '../UITypes'; import { IDType } from './index'; +import { ColumnType } from '~/lib'; const dbTypes = [ 'BIGINT', @@ -794,7 +795,7 @@ export class DatabricksUi { ]; } - static getNowDefaultVal() { + static getCurrentDateDefault(_col: Partial) { return null; } diff --git a/packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts index a96a43ee83..d0cd4e2c38 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts @@ -1,5 +1,6 @@ import UITypes from '../UITypes'; import { IDType } from './index'; +import { ColumnType } from '~/lib'; const dbTypes = [ 'bigint', @@ -969,7 +970,7 @@ export class MssqlUi { ]; } - static getNowDefaultVal() { + static getCurrentDateDefault(_col: Partial) { return null; } diff --git a/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts index 530a3d0bc0..70daed8ba9 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts @@ -1,5 +1,5 @@ import UITypes from '../UITypes'; -import { IDType } from '~/lib'; +import { ColumnType, IDType } from '~/lib'; const dbTypes = [ 'int', @@ -1335,7 +1335,21 @@ export class MysqlUi { return ['COUNTA', 'COUNT', 'DATESTR']; } - static getNowDefaultVal() { + static getCurrentDateDefault(col: Partial) { + // if database datatype timestamp or datetime then return CURRENT_TIMESTAMP + if ( + col.dt && + (col.dt.toLowerCase() === 'timestamp' || + col.dt.toLowerCase() === 'datetime') + ) { + return 'CURRENT_TIMESTAMP'; + } + + // database type is not defined(means column create) and ui datatype is datetime then return CURRENT_TIMESTAMP + // in this scenario it will create column with datatype timestamp/datetime + if (!col.dt && col.uidt === UITypes.DateTime) { + return 'CURRENT_TIMESTAMP'; + } return null; } diff --git a/packages/nocodb-sdk/src/lib/sqlUi/OracleUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/OracleUi.ts index 8062c8b3b4..1e5b4b5e0f 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/OracleUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/OracleUi.ts @@ -1,4 +1,4 @@ -import { NormalColumnRequestType } from '../Api'; +import { ColumnType, NormalColumnRequestType } from '../Api'; import UITypes from '../UITypes'; import { IDType } from './index'; @@ -952,7 +952,7 @@ export class OracleUi { ]; } - static getNowDefaultVal() { + static getCurrentDateDefault(_col: Partial) { return null; } diff --git a/packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts index 608e17da8d..3a9d92b213 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts @@ -1,5 +1,6 @@ import UITypes from '../UITypes'; import { IDType } from './index'; +import { ColumnType } from '~/lib'; const dbTypes = [ 'int', @@ -2032,8 +2033,11 @@ export class PgUi { return []; } - static getNowDefaultVal() { - return 'NOW()'; + static getCurrentDateDefault(col: Partial) { + if (col.uidt === UITypes.DateTime || col.uidt === UITypes.Date) { + return 'NOW()'; + } + return null; } static isEqual(dataType1: string, dataType2: string) { diff --git a/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts index 7ea385ea5e..b3a86cf1bd 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts @@ -1,5 +1,6 @@ import UITypes from '../UITypes'; import { IDType } from './index'; +import { ColumnType } from '~/lib'; const dbTypes = [ 'NUMBER', @@ -1035,7 +1036,7 @@ export class SnowflakeUi { ]; } - static getNowDefaultVal() { + static getCurrentDateDefault(_col: Partial) { return null; } diff --git a/packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts index fbc9fd4628..d2f6d5aea0 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts @@ -1,5 +1,6 @@ import UITypes from '../UITypes'; import { IDType } from './index'; +import { ColumnType } from '~/lib'; const dbTypes = [ 'int', @@ -930,7 +931,7 @@ export class SqliteUi { ]; } - static getNowDefaultVal() { + static getCurrentDateDefault(_col: Partial) { return null; }