Using snowflake-promise
This commit is contained in:
parent
aef0aa78d8
commit
87c0df55f0
|
@ -130,7 +130,6 @@
|
|||
"pouchdb-replication-stream": "1.2.9",
|
||||
"redis": "4",
|
||||
"server-destroy": "1.0.1",
|
||||
"snowflake-sdk": "^1.6.10",
|
||||
"svelte": "^3.38.2",
|
||||
"swagger-parser": "^10.0.3",
|
||||
"to-json-schema": "0.2.5",
|
||||
|
@ -159,7 +158,6 @@
|
|||
"@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",
|
||||
|
@ -176,6 +174,7 @@
|
|||
"path-to-regexp": "^6.2.0",
|
||||
"prettier": "^2.3.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"snowflake-promise": "^4.5.0",
|
||||
"supertest": "^4.0.2",
|
||||
"swagger-jsdoc": "^6.1.0",
|
||||
"ts-jest": "^27.0.3",
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
import { Integration, QueryTypes, SqlQuery } from "../definitions/datasource"
|
||||
import {
|
||||
SnowflakeError,
|
||||
Statement,
|
||||
createConnection,
|
||||
Connection,
|
||||
} from "snowflake-sdk"
|
||||
import { Snowflake } from "snowflake-promise"
|
||||
|
||||
module SnowflakeModule {
|
||||
interface SnowflakeConfig {
|
||||
|
@ -64,38 +59,19 @@ module SnowflakeModule {
|
|||
}
|
||||
|
||||
class SnowflakeIntegration {
|
||||
private client: Connection
|
||||
private client: Snowflake
|
||||
|
||||
constructor(config: SnowflakeConfig) {
|
||||
this.client = createConnection(config)
|
||||
}
|
||||
|
||||
async connectAsync() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.connect(function (err: any, conn: any) {
|
||||
if (err) reject(err)
|
||||
resolve(conn)
|
||||
})
|
||||
})
|
||||
this.client = new Snowflake(config)
|
||||
}
|
||||
|
||||
async internalQuery(query: SqlQuery) {
|
||||
await this.connectAsync()
|
||||
let response: any = await new Promise((resolve, reject) =>
|
||||
this.client.execute({
|
||||
sqlText: query.sql,
|
||||
streamResult: false,
|
||||
complete: (
|
||||
err: SnowflakeError | undefined,
|
||||
stmt: Statement,
|
||||
rows: any[] | undefined
|
||||
) => {
|
||||
if (err) reject(err?.message.split(":")[1] || err?.message)
|
||||
resolve({ rows })
|
||||
},
|
||||
})
|
||||
)
|
||||
return response.rows
|
||||
await this.client.connect()
|
||||
try {
|
||||
return await this.client.execute(query.sql)
|
||||
} catch (err: any) {
|
||||
throw err?.message.split(":")[1] || err?.message
|
||||
}
|
||||
}
|
||||
|
||||
async create(query: SqlQuery) {
|
||||
|
|
Loading…
Reference in New Issue