Browse Source

feat: update Scowflake client and rename the method name

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5613/head
Pranav C 2 years ago
parent
commit
974e213a91
  1. 2
      packages/nocodb/src/db/sql-client/lib/KnexClient.ts
  2. 2
      packages/nocodb/src/db/sql-client/lib/mssql/MssqlClient.ts
  3. 2
      packages/nocodb/src/db/sql-client/lib/mysql/MysqlClient.ts
  4. 2
      packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts
  5. 53
      packages/nocodb/src/db/sql-client/lib/snowflake/SnowflakeClient.ts
  6. 6
      packages/nocodb/src/db/sql-client/lib/sqlite/SqliteClient.ts

2
packages/nocodb/src/db/sql-client/lib/KnexClient.ts

@ -2968,7 +2968,7 @@ class KnexClient extends SqlClient {
}
// todo: add support to complex default values with functions and expressions
validateAndSanitiseDefaultValue(value: string | number | boolean) {
sanitiseDefaultValue(value: string | number | boolean) {
if (value === null || value === undefined) return undefined;
if (typeof value === 'string') {

2
packages/nocodb/src/db/sql-client/lib/mssql/MssqlClient.ts

@ -2577,7 +2577,7 @@ class MssqlClient extends KnexClient {
alterTableColumn(t, n, o, existingQuery, change = 2) {
let query = '';
const defaultValue = this.validateAndSanitiseDefaultValue(n.cdf);
const defaultValue = this.sanitiseDefaultValue(n.cdf);
const shouldSanitize = true;
const scaleAndPrecision =
!getDefaultLengthIsDisabled(n.dt) && n.dtxp

2
packages/nocodb/src/db/sql-client/lib/mysql/MysqlClient.ts

@ -2484,7 +2484,7 @@ class MysqlClient extends KnexClient {
query += n.un ? ' UNSIGNED' : '';
query += n.rqd ? ' NOT NULL' : ' NULL';
query += n.ai ? ' auto_increment' : '';
const defaultValue = this.validateAndSanitiseDefaultValue(n.cdf);
const defaultValue = this.sanitiseDefaultValue(n.cdf);
query += defaultValue
? `
DEFAULT ${defaultValue}`

2
packages/nocodb/src/db/sql-client/lib/pg/PgClient.ts

@ -2685,7 +2685,7 @@ class PGClient extends KnexClient {
alterTableColumn(t, n, o, existingQuery, change = 2) {
let query = '';
const defaultValue = this.validateAndSanitiseDefaultValue(n.cdf);
const defaultValue = this.sanitiseDefaultValue(n.cdf);
const shouldSanitize = true;
if (change === 0) {

53
packages/nocodb/src/db/sql-client/lib/snowflake/SnowflakeClient.ts

@ -2474,7 +2474,7 @@ class SnowflakeClient extends KnexClient {
alterTableColumn(t, n, o, existingQuery, change = 2) {
let query = '';
const defaultValue = getDefaultValue(n);
const defaultValue = this.sanitiseDefaultValue(n);
const shouldSanitize = true;
if (change === 0) {
@ -2534,7 +2534,7 @@ class SnowflakeClient extends KnexClient {
[this.getTnPath(t), n.cn],
shouldSanitize,
);
query += n.cdf ? ` SET DEFAULT ${n.cdf};\n` : ` DROP DEFAULT;\n`;
query += n.cdf ? ` SET DEFAULT ${this.sanitiseDefaultValue(n.cdf)};\n` : ` DROP DEFAULT;\n`;
}
}
return query;
@ -2606,53 +2606,4 @@ class SnowflakeClient extends KnexClient {
}
}
function getDefaultValue(n) {
if (n.cdf === undefined || n.cdf === null) return n.cdf;
switch (n.dt) {
case 'serial':
case 'bigserial':
case 'smallserial':
return '';
break;
case 'boolean':
case 'bool':
case 'tinyint':
case 'int':
case 'samllint':
case 'bigint':
case 'integer':
case 'mediumint':
case 'int2':
case 'int4':
case 'int8':
case 'long':
case 'number':
case 'float':
case 'double':
case 'decimal':
case 'numeric':
case 'real':
case 'double precision':
case 'money':
case 'smallmoney':
case 'dec':
return n.cdf;
break;
case 'datetime':
case 'timestamp':
case 'date':
case 'time':
if (
n.cdf.indexOf('CURRENT_TIMESTAMP') > -1 ||
/\(([\d\w'", ]*)\)$/.test(n.cdf)
) {
return n.cdf;
}
break;
default:
break;
}
return n.cdf;
}
export default SnowflakeClient;

6
packages/nocodb/src/db/sql-client/lib/sqlite/SqliteClient.ts

@ -2019,7 +2019,7 @@ class SqliteClient extends KnexClient {
);
addNewColumnQuery += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : '';
addNewColumnQuery += n.cdf
? ` DEFAULT ${this.validateAndSanitiseDefaultValue(n.cdf)}`
? ` DEFAULT ${this.sanitiseDefaultValue(n.cdf)}`
: !n.rqd
? ' '
: ` DEFAULT ''`;
@ -2047,13 +2047,13 @@ class SqliteClient extends KnexClient {
query = existingQuery ? ',' : '';
query += this.genQuery(`?? ${n.dt}`, [n.cn], shouldSanitize);
query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : '';
query += n.cdf ? ` DEFAULT ${this.validateAndSanitiseDefaultValue(n.cdf)}` : ' ';
query += n.cdf ? ` DEFAULT ${this.sanitiseDefaultValue(n.cdf)}` : ' ';
query += n.rqd ? ` NOT NULL` : ' ';
} else if (change === 1) {
shouldSanitize = true;
query += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize);
query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : '';
query += n.cdf ? ` DEFAULT ${this.validateAndSanitiseDefaultValue(n.cdf)}` : !n.rqd ? ' ' : ` DEFAULT ''`;
query += n.cdf ? ` DEFAULT ${this.sanitiseDefaultValue(n.cdf)}` : !n.rqd ? ' ' : ` DEFAULT ''`;
query += n.rqd ? ` NOT NULL` : ' ';
query = this.genQuery(`ALTER TABLE ?? ${query};`, [t], shouldSanitize);
} else {

Loading…
Cancel
Save