From 87c0df55f0fa625eb9c3e7857b77ac55f10295f8 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Wed, 1 Jun 2022 11:41:41 +0100 Subject: [PATCH] Using snowflake-promise --- packages/server/package.json | 3 +- packages/server/src/integrations/snowflake.ts | 42 ++++--------------- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/packages/server/package.json b/packages/server/package.json index d4e640797c..e256b5bfc8 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -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", diff --git a/packages/server/src/integrations/snowflake.ts b/packages/server/src/integrations/snowflake.ts index f9335ecf4e..711647e5df 100644 --- a/packages/server/src/integrations/snowflake.ts +++ b/packages/server/src/integrations/snowflake.ts @@ -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) {