Detect auto columns

This commit is contained in:
Rory Powell 2021-11-18 10:49:53 +00:00
parent 1d53581f17
commit 681cb1bbbc
1 changed files with 14 additions and 1 deletions

View File

@ -91,6 +91,7 @@ module OracleModule {
TABLE_NAME: string TABLE_NAME: string
COLUMN_NAME: string COLUMN_NAME: string
DATA_TYPE: string DATA_TYPE: string
DATA_DEFAULT: string | null
COLUMN_ID: number COLUMN_ID: number
CONSTRAINT_NAME: string | null CONSTRAINT_NAME: string | null
CONSTRAINT_TYPE: string | null CONSTRAINT_TYPE: string | null
@ -114,6 +115,7 @@ module OracleModule {
interface OracleColumn { interface OracleColumn {
name: string name: string
type: string type: string
default: string | null
id: number id: number
constraints: {[key: string]: OracleConstraint } constraints: {[key: string]: OracleConstraint }
} }
@ -145,6 +147,7 @@ module OracleModule {
tabs.table_name, tabs.table_name,
cols.column_name, cols.column_name,
cols.data_type, cols.data_type,
cols.data_default,
cols.column_id, cols.column_id,
cons.constraint_name, cons.constraint_name,
cons.constraint_type, cons.constraint_type,
@ -183,6 +186,7 @@ module OracleModule {
const tableName = row.TABLE_NAME const tableName = row.TABLE_NAME
const columnName = row.COLUMN_NAME const columnName = row.COLUMN_NAME
const dataType = row.DATA_TYPE const dataType = row.DATA_TYPE
const dataDefault = row.DATA_DEFAULT
const columnId = row.COLUMN_ID const columnId = row.COLUMN_ID
const constraintName = row.CONSTRAINT_NAME const constraintName = row.CONSTRAINT_NAME
const constraintType = row.CONSTRAINT_TYPE const constraintType = row.CONSTRAINT_TYPE
@ -203,6 +207,7 @@ module OracleModule {
column = { column = {
name: columnName, name: columnName,
type: dataType, type: dataType,
default: dataDefault,
id: columnId, id: columnId,
constraints: {} constraints: {}
} }
@ -235,6 +240,14 @@ module OracleModule {
return true return true
} }
private isAutoColumn(column: OracleColumn) {
if (column.default && column.default.toLowerCase().includes("nextval")) {
return true
}
return false
}
/** /**
* Fetches the tables from the oracle table and assigns them to the datasource. * Fetches the tables from the oracle table and assigns them to the datasource.
* @param {*} datasourceId - datasourceId to fetch * @param {*} datasourceId - datasourceId to fetch
@ -270,7 +283,7 @@ module OracleModule {
let fieldSchema = table.schema[columnName] let fieldSchema = table.schema[columnName]
if (!fieldSchema) { if (!fieldSchema) {
fieldSchema = { fieldSchema = {
autocolumn: false, autocolumn: this.isAutoColumn(oracleColumn),
name: columnName, name: columnName,
type: convertType(oracleColumn.type, TYPE_MAP), type: convertType(oracleColumn.type, TYPE_MAP),
} }