Using snowflake-promise

This commit is contained in:
Mel O'Hagan 2022-06-01 11:41:41 +01:00
parent aef0aa78d8
commit 87c0df55f0
2 changed files with 10 additions and 35 deletions

View File

@ -130,7 +130,6 @@
"pouchdb-replication-stream": "1.2.9", "pouchdb-replication-stream": "1.2.9",
"redis": "4", "redis": "4",
"server-destroy": "1.0.1", "server-destroy": "1.0.1",
"snowflake-sdk": "^1.6.10",
"svelte": "^3.38.2", "svelte": "^3.38.2",
"swagger-parser": "^10.0.3", "swagger-parser": "^10.0.3",
"to-json-schema": "0.2.5", "to-json-schema": "0.2.5",
@ -159,7 +158,6 @@
"@types/node": "^15.12.4", "@types/node": "^15.12.4",
"@types/oracledb": "^5.2.1", "@types/oracledb": "^5.2.1",
"@types/redis": "^4.0.11", "@types/redis": "^4.0.11",
"@types/snowflake-sdk": "^1.6.2",
"@typescript-eslint/parser": "5.12.0", "@typescript-eslint/parser": "5.12.0",
"apidoc": "^0.50.2", "apidoc": "^0.50.2",
"babel-jest": "^27.0.2", "babel-jest": "^27.0.2",
@ -176,6 +174,7 @@
"path-to-regexp": "^6.2.0", "path-to-regexp": "^6.2.0",
"prettier": "^2.3.1", "prettier": "^2.3.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"snowflake-promise": "^4.5.0",
"supertest": "^4.0.2", "supertest": "^4.0.2",
"swagger-jsdoc": "^6.1.0", "swagger-jsdoc": "^6.1.0",
"ts-jest": "^27.0.3", "ts-jest": "^27.0.3",

View File

@ -1,10 +1,5 @@
import { Integration, QueryTypes, SqlQuery } from "../definitions/datasource" import { Integration, QueryTypes, SqlQuery } from "../definitions/datasource"
import { import { Snowflake } from "snowflake-promise"
SnowflakeError,
Statement,
createConnection,
Connection,
} from "snowflake-sdk"
module SnowflakeModule { module SnowflakeModule {
interface SnowflakeConfig { interface SnowflakeConfig {
@ -64,38 +59,19 @@ module SnowflakeModule {
} }
class SnowflakeIntegration { class SnowflakeIntegration {
private client: Connection private client: Snowflake
constructor(config: SnowflakeConfig) { constructor(config: SnowflakeConfig) {
this.client = createConnection(config) this.client = new Snowflake(config)
}
async connectAsync() {
return new Promise((resolve, reject) => {
this.client.connect(function (err: any, conn: any) {
if (err) reject(err)
resolve(conn)
})
})
} }
async internalQuery(query: SqlQuery) { async internalQuery(query: SqlQuery) {
await this.connectAsync() await this.client.connect()
let response: any = await new Promise((resolve, reject) => try {
this.client.execute({ return await this.client.execute(query.sql)
sqlText: query.sql, } catch (err: any) {
streamResult: false, throw err?.message.split(":")[1] || err?.message
complete: ( }
err: SnowflakeError | undefined,
stmt: Statement,
rows: any[] | undefined
) => {
if (err) reject(err?.message.split(":")[1] || err?.message)
resolve({ rows })
},
})
)
return response.rows
} }
async create(query: SqlQuery) { async create(query: SqlQuery) {