From c8151b33f7041790601d786173ff8384f2c097f4 Mon Sep 17 00:00:00 2001 From: nicole devillers Date: Wed, 8 Nov 2023 18:05:23 -0800 Subject: [PATCH 1/2] bump typescript version and fix Statement.executePromise type --- package-lock.json | 14 +++---- package.json | 2 +- src/Statement.ts | 93 ++++++++++++++++++++++++++++++++--------------- 3 files changed, 72 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index ae30086..8c90a86 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "np": "^6.5.0", "ts-node": "^9.1.1", "tslint": "^6.1.3", - "typescript": "^3.9.9" + "typescript": "^4.4.3" }, "engines": { "node": ">=10" @@ -7321,9 +7321,9 @@ } }, "node_modules/typescript": { - "version": "3.9.9", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.9.tgz", - "integrity": "sha512-kdMjTiekY+z/ubJCATUPlRDl39vXYiMV9iyeMuEuXZh2we6zz80uovNN2WlAxmmdE/Z/YQe+EbOEXB5RHEED3w==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -13687,9 +13687,9 @@ } }, "typescript": { - "version": "3.9.9", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.9.tgz", - "integrity": "sha512-kdMjTiekY+z/ubJCATUPlRDl39vXYiMV9iyeMuEuXZh2we6zz80uovNN2WlAxmmdE/Z/YQe+EbOEXB5RHEED3w==", + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "dev": true }, "unique-string": { diff --git a/package.json b/package.json index 6a52ace..7668e93 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "np": "^6.5.0", "ts-node": "^9.1.1", "tslint": "^6.1.3", - "typescript": "^3.9.9" + "typescript": "^4.4.3" }, "dependencies": { "snowflake-sdk": "^1.9.0" diff --git a/src/Statement.ts b/src/Statement.ts index ef6cc2f..e5dec36 100644 --- a/src/Statement.ts +++ b/src/Statement.ts @@ -1,14 +1,14 @@ -import { ExecuteOptions } from './types/ExecuteOptions'; -import { Readable } from 'stream'; -import { Snowflake } from './Snowflake'; -import { StatementAlreadyExecutedError } from './types/StatementAlreadyExecutedError'; -import { StatementNotExecutedError } from './types/StatementNotExecutedError'; -import { StreamRowsOptions } from './types/StreamRowsOptions'; +import { ExecuteOptions } from "./types/ExecuteOptions"; +import { Readable } from "stream"; +import { Snowflake } from "./Snowflake"; +import { StatementAlreadyExecutedError } from "./types/StatementAlreadyExecutedError"; +import { StatementNotExecutedError } from "./types/StatementNotExecutedError"; +import { StreamRowsOptions } from "./types/StreamRowsOptions"; export class Statement { private rows: any[] = null; private stmt: any = null; - private executePromise: Promise = null; + private executePromise: Promise = null; /** * @param connection the connection object from the SDK @@ -27,15 +27,21 @@ export class Statement { * @return Promise */ execute() { - if (this.executePromise) { throw new StatementAlreadyExecutedError(); } + if (this.executePromise) { + throw new StatementAlreadyExecutedError(); + } this.executePromise = new Promise((resolve, reject) => { let startTime: number; - this.executeOptions['complete'] = (err, stmt, rows) => { + this.executeOptions["complete"] = (err, stmt, rows) => { const elapsed = Date.now() - startTime; - if (err) { reject(err); } - if (this.logSql) { this.log(elapsed); } + if (err) { + reject(err); + } + if (this.logSql) { + this.log(elapsed); + } this.rows = rows; resolve(); }; @@ -50,10 +56,13 @@ export class Statement { /** Cancel a currently-executing Statement. */ cancel() { return new Promise((resolve, reject) => { - this.stmt.cancel(err => { - if (err) { reject(err); } - else { resolve(); } - }) + this.stmt.cancel((err) => { + if (err) { + reject(err); + } else { + resolve(); + } + }); }); } @@ -62,7 +71,9 @@ export class Statement { * @throws if the Statement was not in streaming mode */ getRows() { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.executePromise.then(() => this.rows); } @@ -71,25 +82,33 @@ export class Statement { * @throws if the statement was in non-streaming mode */ streamRows(options: StreamRowsOptions = {}): Readable { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.stmt.streamRows(options); } /** this statement's SQL text */ getSqlText(): string { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.stmt.getSqlText(); } /** the current status of this statement */ getStatus(): string { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.stmt.getStatus(); } /** the columns produced by this statement */ getColumns(): object[] { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.stmt.getColumns(); } @@ -100,19 +119,25 @@ export class Statement { * that name, the first column with the specified name will be returned. */ getColumn(columnIdentifier: string | number): object { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.stmt.getColumn(columnIdentifier); } /** the number of rows returned by this statement */ getNumRows(): number { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.stmt.getNumRows(); } /** the number of rows updated by this statement */ getNumUpdatedRows(): number { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.stmt.getNumUpdatedRows(); } @@ -122,13 +147,17 @@ export class Statement { * executing. */ getSessionState() { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.stmt.getSessionState(); } /** the request id that was used when the statement was issued */ getRequestId(): string { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.stmt.getRequestId(); } @@ -138,13 +167,15 @@ export class Statement { * yet, this method will return undefined. */ getStatementId(): object { - if (!this.executePromise) { throw new StatementNotExecutedError(); } + if (!this.executePromise) { + throw new StatementNotExecutedError(); + } return this.stmt.getStatementId(); } /** log execution details */ private log(elapsedTime: number) { - let logMessage = 'Executed'; + let logMessage = "Executed"; const state = this.getSessionState(); if (state) { @@ -152,10 +183,14 @@ export class Statement { } logMessage += `: ${this.getSqlText()}`; - if (logMessage[logMessage.length - 1] !== ';') { logMessage += ';'; } + if (logMessage[logMessage.length - 1] !== ";") { + logMessage += ";"; + } if (this.executeOptions.binds) { - logMessage += ` with binds: ${JSON.stringify(this.executeOptions.binds)};` + logMessage += ` with binds: ${JSON.stringify( + this.executeOptions.binds + )};`; } logMessage += ` Elapsed time: ${elapsedTime}ms`; From 5517be6aa49ce7c01506b6ca1fe022e50d9777ab Mon Sep 17 00:00:00 2001 From: nicole devillers Date: Wed, 8 Nov 2023 18:07:23 -0800 Subject: [PATCH 2/2] revert formatting changes --- src/Statement.ts | 91 +++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 63 deletions(-) diff --git a/src/Statement.ts b/src/Statement.ts index e5dec36..5fedafe 100644 --- a/src/Statement.ts +++ b/src/Statement.ts @@ -1,9 +1,9 @@ -import { ExecuteOptions } from "./types/ExecuteOptions"; -import { Readable } from "stream"; -import { Snowflake } from "./Snowflake"; -import { StatementAlreadyExecutedError } from "./types/StatementAlreadyExecutedError"; -import { StatementNotExecutedError } from "./types/StatementNotExecutedError"; -import { StreamRowsOptions } from "./types/StreamRowsOptions"; +import { ExecuteOptions } from './types/ExecuteOptions'; +import { Readable } from 'stream'; +import { Snowflake } from './Snowflake'; +import { StatementAlreadyExecutedError } from './types/StatementAlreadyExecutedError'; +import { StatementNotExecutedError } from './types/StatementNotExecutedError'; +import { StreamRowsOptions } from './types/StreamRowsOptions'; export class Statement { private rows: any[] = null; @@ -27,21 +27,15 @@ export class Statement { * @return Promise */ execute() { - if (this.executePromise) { - throw new StatementAlreadyExecutedError(); - } + if (this.executePromise) { throw new StatementAlreadyExecutedError(); } this.executePromise = new Promise((resolve, reject) => { let startTime: number; - this.executeOptions["complete"] = (err, stmt, rows) => { + this.executeOptions['complete'] = (err, stmt, rows) => { const elapsed = Date.now() - startTime; - if (err) { - reject(err); - } - if (this.logSql) { - this.log(elapsed); - } + if (err) { reject(err); } + if (this.logSql) { this.log(elapsed); } this.rows = rows; resolve(); }; @@ -56,13 +50,10 @@ export class Statement { /** Cancel a currently-executing Statement. */ cancel() { return new Promise((resolve, reject) => { - this.stmt.cancel((err) => { - if (err) { - reject(err); - } else { - resolve(); - } - }); + this.stmt.cancel(err => { + if (err) { reject(err); } + else { resolve(); } + }) }); } @@ -71,9 +62,7 @@ export class Statement { * @throws if the Statement was not in streaming mode */ getRows() { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.executePromise.then(() => this.rows); } @@ -82,33 +71,25 @@ export class Statement { * @throws if the statement was in non-streaming mode */ streamRows(options: StreamRowsOptions = {}): Readable { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.stmt.streamRows(options); } /** this statement's SQL text */ getSqlText(): string { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.stmt.getSqlText(); } /** the current status of this statement */ getStatus(): string { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.stmt.getStatus(); } /** the columns produced by this statement */ getColumns(): object[] { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.stmt.getColumns(); } @@ -119,25 +100,19 @@ export class Statement { * that name, the first column with the specified name will be returned. */ getColumn(columnIdentifier: string | number): object { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.stmt.getColumn(columnIdentifier); } /** the number of rows returned by this statement */ getNumRows(): number { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.stmt.getNumRows(); } /** the number of rows updated by this statement */ getNumUpdatedRows(): number { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.stmt.getNumUpdatedRows(); } @@ -147,17 +122,13 @@ export class Statement { * executing. */ getSessionState() { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.stmt.getSessionState(); } /** the request id that was used when the statement was issued */ getRequestId(): string { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.stmt.getRequestId(); } @@ -167,15 +138,13 @@ export class Statement { * yet, this method will return undefined. */ getStatementId(): object { - if (!this.executePromise) { - throw new StatementNotExecutedError(); - } + if (!this.executePromise) { throw new StatementNotExecutedError(); } return this.stmt.getStatementId(); } /** log execution details */ private log(elapsedTime: number) { - let logMessage = "Executed"; + let logMessage = 'Executed'; const state = this.getSessionState(); if (state) { @@ -183,14 +152,10 @@ export class Statement { } logMessage += `: ${this.getSqlText()}`; - if (logMessage[logMessage.length - 1] !== ";") { - logMessage += ";"; - } + if (logMessage[logMessage.length - 1] !== ';') { logMessage += ';'; } if (this.executeOptions.binds) { - logMessage += ` with binds: ${JSON.stringify( - this.executeOptions.binds - )};`; + logMessage += ` with binds: ${JSON.stringify(this.executeOptions.binds)};` } logMessage += ` Elapsed time: ${elapsedTime}ms`;