Use global sql type map, update base integration type defs

This commit is contained in:
Rory Powell 2021-11-22 11:38:17 +00:00
parent 85ef7838af
commit 2edb24fa86
3 changed files with 17 additions and 22 deletions

View File

@ -1,6 +1,6 @@
export interface IntegrationBase { export interface IntegrationBase {
create?(query: any): Promise<[any]> create?(query: any): Promise<any[]>
read?(query: any): Promise<[any]> read?(query: any): Promise<any[]>
update?(query: any): Promise<[any]> update?(query: any): Promise<any[]>
delete?(query: any): Promise<[any]> delete?(query: any): Promise<any[]>
} }

View File

@ -9,7 +9,7 @@ import {
finaliseExternalTables, finaliseExternalTables,
getSqlQuery, getSqlQuery,
buildExternalTableId, buildExternalTableId,
convertType, convertSqlType,
} from "./utils" } from "./utils"
import oracledb, { import oracledb, {
ExecuteOptions, ExecuteOptions,
@ -82,15 +82,6 @@ module OracleModule {
const UNSUPPORTED_TYPES = ["BLOB", "CLOB", "NCLOB"] const UNSUPPORTED_TYPES = ["BLOB", "CLOB", "NCLOB"]
const TYPE_MAP = {
long: FieldTypes.LONGFORM,
number: FieldTypes.NUMBER,
binary_float: FieldTypes.NUMBER,
binary_double: FieldTypes.NUMBER,
timestamp: FieldTypes.DATETIME,
date: FieldTypes.DATETIME,
}
/** /**
* Raw query response * Raw query response
*/ */
@ -292,7 +283,7 @@ module OracleModule {
return FieldTypes.BOOLEAN return FieldTypes.BOOLEAN
} }
return convertType(column.type, TYPE_MAP) return convertSqlType(column.type)
} }
/** /**
@ -393,26 +384,26 @@ module OracleModule {
return oracledb.getConnection(attributes) return oracledb.getConnection(attributes)
} }
async create(query: SqlQuery | string) { async create(query: SqlQuery | string): Promise<any[]> {
const response = await this.internalQuery(getSqlQuery(query)) const response = await this.internalQuery<any>(getSqlQuery(query))
return response.rows && response.rows.length return response.rows && response.rows.length
? response.rows ? response.rows
: [{ created: true }] : [{ created: true }]
} }
async read(query: SqlQuery | string) { async read(query: SqlQuery | string): Promise<any[]> {
const response = await this.internalQuery(getSqlQuery(query)) const response = await this.internalQuery<any>(getSqlQuery(query))
return response.rows return response.rows ? response.rows : []
} }
async update(query: SqlQuery | string) { async update(query: SqlQuery | string): Promise<any[]> {
const response = await this.internalQuery(getSqlQuery(query)) const response = await this.internalQuery(getSqlQuery(query))
return response.rows && response.rows.length return response.rows && response.rows.length
? response.rows ? response.rows
: [{ updated: true }] : [{ updated: true }]
} }
async delete(query: SqlQuery | string) { async delete(query: SqlQuery | string): Promise<any[]> {
const response = await this.internalQuery(getSqlQuery(query)) const response = await this.internalQuery(getSqlQuery(query))
return response.rows && response.rows.length return response.rows && response.rows.length
? response.rows ? response.rows

View File

@ -32,6 +32,10 @@ const SQL_TYPE_MAP = {
fixed: FieldTypes.NUMBER, fixed: FieldTypes.NUMBER,
datetime: FieldTypes.DATETIME, datetime: FieldTypes.DATETIME,
tinyint: FieldTypes.BOOLEAN, tinyint: FieldTypes.BOOLEAN,
long: FieldTypes.LONGFORM,
number: FieldTypes.NUMBER,
binary_float: FieldTypes.NUMBER,
binary_double: FieldTypes.NUMBER,
} }
export enum SqlClients { export enum SqlClients {