Added types and error handling
This commit is contained in:
parent
570aeecdc3
commit
fe3a774db3
|
@ -158,6 +158,7 @@
|
|||
"@types/node": "^15.12.4",
|
||||
"@types/oracledb": "^5.2.1",
|
||||
"@types/redis": "^4.0.11",
|
||||
"@types/snowflake-sdk": "^1.6.2",
|
||||
"@typescript-eslint/parser": "5.12.0",
|
||||
"apidoc": "^0.50.2",
|
||||
"babel-jest": "^27.0.2",
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import { Integration, QueryTypes, SqlQuery } from "../definitions/datasource"
|
||||
const snowflake = require("snowflake-sdk")
|
||||
import {
|
||||
SnowflakeError,
|
||||
Statement,
|
||||
createConnection,
|
||||
Connection,
|
||||
} from "snowflake-sdk"
|
||||
|
||||
module SnowflakeModule {
|
||||
interface SnowflakeConfig {
|
||||
|
@ -59,17 +64,15 @@ module SnowflakeModule {
|
|||
}
|
||||
|
||||
class SnowflakeIntegration {
|
||||
private config: SnowflakeConfig
|
||||
private client: any
|
||||
private client: Connection
|
||||
|
||||
constructor(config: SnowflakeConfig) {
|
||||
this.config = config
|
||||
this.client = snowflake.createConnection(config)
|
||||
this.client = createConnection(config)
|
||||
}
|
||||
|
||||
async connAsync(connection: any) {
|
||||
async connectAsync() {
|
||||
return new Promise((resolve, reject) => {
|
||||
connection.connect(function (err: any, conn: any) {
|
||||
this.client.connect(function (err: any, conn: any) {
|
||||
if (err) reject(err)
|
||||
resolve(conn)
|
||||
})
|
||||
|
@ -77,12 +80,17 @@ module SnowflakeModule {
|
|||
}
|
||||
|
||||
async read(query: SqlQuery) {
|
||||
let connection: any = await this.connAsync(this.client)
|
||||
await this.connectAsync()
|
||||
let response: any = await new Promise((resolve, reject) =>
|
||||
connection.execute({
|
||||
this.client.execute({
|
||||
sqlText: query.sql,
|
||||
streamResult: false,
|
||||
complete: (err: any, statement: any, rows: any) => {
|
||||
complete: (
|
||||
err: SnowflakeError | undefined,
|
||||
stmt: Statement,
|
||||
rows: any[] | undefined
|
||||
) => {
|
||||
if (err) reject(err?.message.split(":")[1] || err?.message)
|
||||
resolve({ rows })
|
||||
},
|
||||
})
|
||||
|
|
|
@ -2545,6 +2545,13 @@
|
|||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/generic-pool@*":
|
||||
version "3.1.10"
|
||||
resolved "https://registry.yarnpkg.com/@types/generic-pool/-/generic-pool-3.1.10.tgz#ed21e0ec798bc5f77bb324e1a5c5c9bf335c1d9e"
|
||||
integrity sha512-WRT/9taXh9XJRA9yvrbC02IqGZhK9GbFE/vuP2LeSLrqmDzz5wdXsH0Ige/F+3+rbbZfwH3LEazDsU0JiSV3vA==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/global-agent@^2.1.1":
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/global-agent/-/global-agent-2.1.1.tgz#3f93185e48a3a36e377a52a8301320cd162a831b"
|
||||
|
@ -2770,6 +2777,14 @@
|
|||
"@types/mime" "^1"
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/snowflake-sdk@^1.6.2":
|
||||
version "1.6.6"
|
||||
resolved "https://registry.yarnpkg.com/@types/snowflake-sdk/-/snowflake-sdk-1.6.6.tgz#df066a660695d0689c5d36cb4e1dbde8f815a9e8"
|
||||
integrity sha512-oGdzQJONiv5UxaSsrIS49IvdcQRoPt6HTqIM8c0JTCIqEwGrsuqBq317PdLntM9SVc8BcDOYeAZTNdlISSSzwQ==
|
||||
dependencies:
|
||||
"@types/generic-pool" "*"
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/stack-utils@^1.0.1":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
|
||||
|
|
Loading…
Reference in New Issue