Browse Source

fix(api): table create method corrections

feat/oracle-support
Pranav C 2 years ago committed by Pranav C
parent
commit
82c9b15c85
  1. 299
      packages/nocodb-sdk/src/lib/sqlUi/OracleUi.ts
  2. 13
      packages/nocodb/src/lib/db/sql-client/lib/oracle/OracleClient.ts

299
packages/nocodb-sdk/src/lib/sqlUi/OracleUi.ts

@ -660,7 +660,7 @@ export class OracleUi {
{ {
const isAutoIncId = idType === 'AI'; const isAutoIncId = idType === 'AI';
const isAutoGenId = idType === 'AG'; const isAutoGenId = idType === 'AG';
colProp.dt = isAutoGenId ? 'varchar' : 'integer'; colProp.dt = isAutoGenId ? 'VARCHAR2' : 'NUMBER';
colProp.pk = true; colProp.pk = true;
colProp.un = isAutoIncId; colProp.un = isAutoIncId;
colProp.ai = isAutoIncId; colProp.ai = isAutoIncId;
@ -669,43 +669,43 @@ export class OracleUi {
} }
break; break;
case 'ForeignKey': case 'ForeignKey':
colProp.dt = 'varchar'; colProp.dt = 'NUMBER';
break; break;
case 'SingleLineText': case 'SingleLineText':
colProp.dt = 'varchar'; colProp.dt = 'VARCHAR2';
break; break;
case 'LongText': case 'LongText':
colProp.dt = 'clob'; colProp.dt = 'CLOB';
break; break;
case 'Attachment': case 'Attachment':
colProp.dt = 'clob'; colProp.dt = 'CLOB';
break; break;
case 'Checkbox': case 'Checkbox':
colProp.dt = 'tinyint'; colProp.dt = 'NUMBER';
colProp.dtxp = 1; colProp.dtxp = 1;
colProp.cdf = '0'; colProp.cdf = '0';
break; break;
case 'MultiSelect': case 'MultiSelect':
colProp.dt = 'varchar2'; colProp.dt = 'VARCHAR2';
break; break;
case 'SingleSelect': case 'SingleSelect':
colProp.dt = 'varchar2'; colProp.dt = 'VARCHAR2';
break; break;
case 'Collaborator': case 'Collaborator':
colProp.dt = 'varchar'; colProp.dt = 'VARCHAR2';
break; break;
case 'Date': case 'Date':
colProp.dt = 'varchar'; colProp.dt = 'DATE';
break; break;
case 'Year': case 'Year':
colProp.dt = 'year'; colProp.dt = 'NUMBER';
break; break;
case 'Time': case 'Time':
colProp.dt = 'time'; colProp.dt = 'DATE';
break; break;
case 'PhoneNumber': case 'PhoneNumber':
colProp.dt = 'varchar'; colProp.dt = 'VARCHAR2';
colProp.validate = { colProp.validate = {
func: ['isMobilePhone'], func: ['isMobilePhone'],
args: [''], args: [''],
@ -713,7 +713,7 @@ export class OracleUi {
}; };
break; break;
case 'Email': case 'Email':
colProp.dt = 'varchar'; colProp.dt = 'VARCHAR2';
colProp.validate = { colProp.validate = {
func: ['isEmail'], func: ['isEmail'],
args: [''], args: [''],
@ -721,7 +721,7 @@ export class OracleUi {
}; };
break; break;
case 'URL': case 'URL':
colProp.dt = 'varchar'; colProp.dt = 'VARCHAR2';
colProp.validate = { colProp.validate = {
func: ['isURL'], func: ['isURL'],
args: [''], args: [''],
@ -729,13 +729,13 @@ export class OracleUi {
}; };
break; break;
case 'Number': case 'Number':
colProp.dt = 'integer'; colProp.dt = 'NUMBER';
break; break;
case 'Decimal': case 'Decimal':
colProp.dt = 'decimal'; colProp.dt = 'NUMBER';
break; break;
case 'Currency': case 'Currency':
colProp.dt = 'decimal'; colProp.dt = 'NUMBER';
colProp.validate = { colProp.validate = {
func: ['isCurrency'], func: ['isCurrency'],
args: [''], args: [''],
@ -743,47 +743,47 @@ export class OracleUi {
}; };
break; break;
case 'Percent': case 'Percent':
colProp.dt = 'double'; colProp.dt = 'NUMBER';
break; break;
case 'Duration': case 'Duration':
colProp.dt = 'integer'; colProp.dt = 'NUMBER';
break; break;
case 'Rating': case 'Rating':
colProp.dt = 'integer'; colProp.dt = 'NUMBER';
colProp.cdf = '0'; colProp.cdf = '0';
break; break;
case 'Formula': case 'Formula':
colProp.dt = 'varchar'; colProp.dt = 'VARCHAR2';
break; break;
case 'Rollup': case 'Rollup':
colProp.dt = 'varchar'; colProp.dt = 'VARCHAR2';
break; break;
case 'Count': case 'Count':
colProp.dt = 'integer'; colProp.dt = 'NUMBER';
break; break;
case 'Lookup': case 'Lookup':
colProp.dt = 'varchar'; colProp.dt = 'VARCHAR2';
break; break;
case 'DateTime': case 'DateTime':
colProp.dt = 'timestamp'; colProp.dt = 'TIMESTAMP';
break; break;
case 'CreateTime': case 'CreateTime':
colProp.dt = 'timestamp'; colProp.dt = 'TIMESTAMP';
break; break;
case 'LastModifiedTime': case 'LastModifiedTime':
colProp.dt = 'timestamp'; colProp.dt = 'TIMESTAMP';
break; break;
case 'AutoNumber': case 'AutoNumber':
colProp.dt = 'integer'; colProp.dt = 'NUMBER';
break; break;
case 'Barcode': case 'Barcode':
colProp.dt = 'varchar'; colProp.dt = 'varchar';
break; break;
case 'Button': case 'Button':
colProp.dt = 'varchar'; colProp.dt = 'VARCHAR2';
break; break;
default: default:
colProp.dt = 'varchar'; colProp.dt = 'VARCHAR2';
break; break;
} }
return colProp; return colProp;
@ -792,44 +792,10 @@ export class OracleUi {
// Ref - https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT513 // Ref - https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT513
static getDataTypeListForUiType(col: { uidt?: UITypes }, idType: IDType) { static getDataTypeListForUiType(col: { uidt?: UITypes }, idType: IDType) {
[
'CHAR',
'VARCHAR',
'VARCHAR2',
'NUMBER',
'NCHAR',
'NVARCHAR2',
'CLOB',
'NCLOB',
'BINARY_FLOAT',
'BINARY_DOUBLE',
'DATE',
'TIMESTAMP',
'TIMESTAMP WITH LOCAL TIME ZONE',
'TIMESTAMP WITH TIME ZONE',
'BLOB',
'CLOB',
'NCLOB',
'BFILE',
'RAW',
'LONG RAW',
'ROWID',
'UROWID',
'XMLType',
'UriType',
];
switch (col.uidt) { switch (col.uidt) {
case 'ID': case 'ID':
if (idType === 'AG') { if (idType === 'AG') {
return ['char', 'character', 'character varying']; return ['VARCHAR2', 'VARCHAR', 'NCHAR', 'NVARCHAR2'];
} else if (idType === 'AI') { } else if (idType === 'AI') {
return ['NUMBER']; return ['NUMBER'];
} else { } else {
@ -871,25 +837,7 @@ export class OracleUi {
'NCLOB', 'NCLOB',
]; ];
case 'Checkbox': case 'Checkbox':
return [ return ['NUMBER'];
'bit',
'bool',
'int2',
'int4',
'int8',
'boolean',
'smallint',
'int',
'integer',
'bigint',
'bigserial',
'char',
'int4range',
'int8range',
'serial',
'serial2',
'serial8',
];
case 'MultiSelect': case 'MultiSelect':
return [ return [
@ -914,26 +862,33 @@ export class OracleUi {
]; ];
case 'Year': case 'Year':
return ['int']; return ['NUMBER'];
case 'Time': case 'Time':
return [ return ['DATE', 'VARCHAR', 'VARCHAR2'];
'time',
'time without time zone',
'timestamp',
'timestamp without time zone',
'timestamptz',
'timestamp with time zone',
'timetz',
'time with time zone',
];
case 'PhoneNumber': case 'PhoneNumber':
case 'Email': case 'Email':
return ['character varying']; return [
'CHAR',
'VARCHAR',
'VARCHAR2',
'NCHAR',
'NVARCHAR2',
'CLOB',
'NCLOB',
];
case 'URL': case 'URL':
return ['character varying', 'text']; return [
'CHAR',
'VARCHAR',
'VARCHAR2',
'NCHAR',
'NVARCHAR2',
'CLOB',
'NCLOB',
];
case 'Number': case 'Number':
return ['NUMBER']; return ['NUMBER'];
@ -942,157 +897,37 @@ export class OracleUi {
return ['NUMBER']; return ['NUMBER'];
case 'Currency': case 'Currency':
return [ return ['NUMBER'];
'int',
'integer',
'bigint',
'bigserial',
'int2',
'int4',
'int8',
'serial',
'serial2',
'serial8',
'double precision',
'money',
'float4',
'float8',
'numeric',
];
case 'Percent': case 'Percent':
return [ return ['NUMBER'];
'int',
'integer',
'bigint',
'bigserial',
'int2',
'int4',
'int8',
'serial',
'serial2',
'serial8',
'double precision',
'float4',
'float8',
'smallint',
'smallserial',
'numeric',
];
case 'Duration': case 'Duration':
return [ return ['NUMBER'];
'int',
'integer',
'bigint',
'bigserial',
'int2',
'int4',
'int8',
'serial',
'serial2',
'serial8',
'double precision',
'float4',
'float8',
'smallint',
'smallserial',
'numeric',
];
case 'Rating': case 'Rating':
return [ return ['NUMBER'];
'int',
'integer',
'bigint',
'bigserial',
'int2',
'int4',
'int8',
'serial',
'serial2',
'serial8',
'double precision',
'float4',
'float8',
'smallint',
'smallserial',
'numeric',
];
case 'Formula':
return ['text', 'character varying'];
case 'Rollup':
return ['character varying'];
case 'Count': case 'Count':
return [ return ['NUMBER'];
'int',
'integer',
'bigint',
'bigserial',
'int2',
'int4',
'int8',
'serial',
'serial2',
'serial8',
'smallint',
'smallserial',
];
case 'Lookup':
return ['character varying'];
case 'Date': case 'Date':
return [ return [
'date', 'DATE',
'timestamp',
'timestamp without time zone', 'TIMESTAMP',
'timestamptz', 'TIMESTAMP WITH LOCAL TIME ZONE',
'timestamp with time zone', 'TIMESTAMP WITH TIME ZONE',
]; ];
case 'DateTime': case 'DateTime':
case 'CreateTime': case 'CreateTime':
case 'LastModifiedTime': case 'LastModifiedTime':
return [ return [
'timestamp', 'DATE',
'timestamp without time zone',
'timestamptz',
'timestamp with time zone',
];
case 'AutoNumber':
return [
'int',
'integer',
'bigint',
'bigserial',
'int2',
'int4',
'int8',
'serial',
'serial2',
'serial8',
'smallint',
'smallserial',
];
case 'Barcode':
return ['character varying'];
case 'Geometry': 'TIMESTAMP',
return [ 'TIMESTAMP WITH LOCAL TIME ZONE',
'polygon', 'TIMESTAMP WITH TIME ZONE',
'point',
'circle',
'box',
'line',
'lseg',
'path',
'circle',
]; ];
case 'Button': case 'Button':

13
packages/nocodb/src/lib/db/sql-client/lib/oracle/OracleClient.ts

@ -2041,13 +2041,14 @@ class OracleClient extends KnexClient {
query += scale ? `,${scale}` : ''; query += scale ? `,${scale}` : '';
query += n.dtxp && n.dtxp !== ' ' ? ')' : ''; query += n.dtxp && n.dtxp !== ' ' ? ')' : '';
// todo: `IDENTITY` is not supported in older version,
// add a fallback with sequence or trigger
if (n.ai) {
query += ' GENERATED BY DEFAULT ON NULL AS IDENTITY';
} else {
query += n.rqd ? ' NOT NULL' : ' NULL'; query += n.rqd ? ' NOT NULL' : ' NULL';
query += defaultValue ? ` DEFAULT ${defaultValue}` : '';
query += n.ai }
? ' GENERATED BY DEFAULT ON NULL AS IDENTITY'
: defaultValue
? ` DEFAULT ${defaultValue}`
: '';
} else if (change === 1) { } else if (change === 1) {
query += ` ADD ${n.cn} ${n.dt}`; query += ` ADD ${n.cn} ${n.dt}`;

Loading…
Cancel
Save