mirror of
https://github.com/FlipsideCrypto/snowflake-promise.git
synced 2026-02-06 03:07:13 +00:00
initial commit
This commit is contained in:
commit
5a4ca064ce
11
.editorconfig
Normal file
11
.editorconfig
Normal file
@ -0,0 +1,11 @@
|
||||
# Editor config settings for foureyes-admin
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
tab_width = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
62
.gitignore
vendored
Normal file
62
.gitignore
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# Project-specific ignores
|
||||
prod
|
||||
src/test.ts
|
||||
11
.npmignore
Normal file
11
.npmignore
Normal file
@ -0,0 +1,11 @@
|
||||
# nyc test coverage report
|
||||
.nyc_output
|
||||
coverage
|
||||
|
||||
# editor settings
|
||||
.vscode
|
||||
.editorconfig
|
||||
|
||||
# unit tests
|
||||
test
|
||||
test/aws.json
|
||||
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"eg2.tslint"
|
||||
]
|
||||
}
|
||||
28
.vscode/launch.json
vendored
Normal file
28
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
{
|
||||
// Use IntelliSense to find out which attributes exist for node debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Program",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/src/app.ts",
|
||||
"cwd": "${workspaceRoot}",
|
||||
"outFiles": [ "${workspaceRoot}/prod/**/*.js" ],
|
||||
"sourceMaps": true,
|
||||
"preLaunchTask": "build"
|
||||
},
|
||||
{
|
||||
"name": "Launch test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/src/test.ts",
|
||||
"cwd": "${workspaceRoot}",
|
||||
"outFiles": [ "${workspaceRoot}/prod/**/*.js" ],
|
||||
"sourceMaps": true,
|
||||
"preLaunchTask": "build"
|
||||
}
|
||||
]
|
||||
}
|
||||
19
.vscode/settings.json
vendored
Normal file
19
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
// Project-specific settings for Visual Studio Code
|
||||
{
|
||||
"editor.tabSize": 2,
|
||||
"editor.insertSpaces": true,
|
||||
"files.trimTrailingWhitespace": true,
|
||||
"files.insertFinalNewline": true,
|
||||
"files.exclude": {
|
||||
"**/prod": true,
|
||||
"**/node_modules": true,
|
||||
"**/coverage": true,
|
||||
"**/cache": true,
|
||||
"sessions.db": true
|
||||
},
|
||||
"tslint.autoFixOnSave": true,
|
||||
"typescript.tsdk": "./node_modules/typescript/lib",
|
||||
"search.useIgnoreFilesByDefault": true,
|
||||
"files.defaultLanguage": "typescript",
|
||||
"files.eol": "\n"
|
||||
}
|
||||
15
.vscode/tasks.json
vendored
Normal file
15
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"type": "npm",
|
||||
"script": "build",
|
||||
"problemMatcher": [
|
||||
"$tsc"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
7
LICENSE.txt
Normal file
7
LICENSE.txt
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright (c) 2017-present Nate Silva and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
45
README.md
Normal file
45
README.md
Normal file
@ -0,0 +1,45 @@
|
||||
# snowflake-promise
|
||||
|
||||
A Promise-based interface to your [Snowflake](https://www.snowflake.net/) data warehouse.
|
||||
|
||||
This is a wrapper for the [Snowflake SDK](https://www.npmjs.com/package/snowflake-sdk) for Node.js. It provides a Promise-based API instead of the core callback-based API.
|
||||
|
||||
## Installation
|
||||
|
||||
`npm i snowflake-promise`
|
||||
|
||||
## Basic usage
|
||||
|
||||
```typescript
|
||||
const Snowflake = require('snowflake-promise').Snowflake;
|
||||
// or, for TypeScript:
|
||||
import { Snowflake } from 'snowflake-promise';
|
||||
|
||||
async function main() {
|
||||
const snowflake = new Snowflake({
|
||||
account: '<account name>',
|
||||
username: '<username>',
|
||||
password: '<password>',
|
||||
database: 'SNOWFLAKE_SAMPLE_DATA',
|
||||
schema: 'TPCH_SF1',
|
||||
warehouse: 'DEMO_WH'
|
||||
});
|
||||
|
||||
await snowflake.connect();
|
||||
|
||||
const rows = await snowflake.execute(
|
||||
'SELECT COUNT(*) FROM CUSTOMER WHERE C_MKTSEGMENT=:1',
|
||||
['AUTOMOBILE']
|
||||
);
|
||||
|
||||
console.log(rows);
|
||||
}
|
||||
|
||||
main();
|
||||
```
|
||||
|
||||
## More examples
|
||||
|
||||
* [Streaming result rows](../../examples/streaming.js)
|
||||
* [Using traditional Promise `then` syntax (and older versions of Node.js)](../../examples/oldSchool.js)
|
||||
* Node 4.0.0 is the oldest supported version
|
||||
48
examples/oldSchool.js
Normal file
48
examples/oldSchool.js
Normal file
@ -0,0 +1,48 @@
|
||||
//
|
||||
// This example shows how to use the library in traditional Promise style. You
|
||||
// might do this if you are using an older version of Node that doesn’t support
|
||||
// async/await, or simply if you prefer the Promise/then syntax.
|
||||
//
|
||||
// (You could also transpile async/await code using TypeScript or Babel, which
|
||||
// allows it to run on older versions of Node.)
|
||||
//
|
||||
// This library supports Node 4.0.0 and higher.
|
||||
//
|
||||
|
||||
//
|
||||
// Use this when processing large datasets (or when retrieving only a few rows
|
||||
// from a large result set). This is common when doing batch processing.
|
||||
//
|
||||
// This avoids loading the entire result set into memory, and lets you work on
|
||||
// one row at a time.
|
||||
//
|
||||
|
||||
var Snowflake = require('snowflake-promise').Snowflake;
|
||||
|
||||
function main() {
|
||||
var snowflake = new Snowflake({
|
||||
account: '<account name>',
|
||||
username: '<username>',
|
||||
password: '<password>',
|
||||
database: 'SNOWFLAKE_SAMPLE_DATA',
|
||||
schema: 'TPCH_SF1',
|
||||
warehouse: 'DEMO_WH'
|
||||
});
|
||||
|
||||
snowflake.connect()
|
||||
.then(function() {
|
||||
return snowflake.execute(
|
||||
'SELECT COUNT(*) FROM CUSTOMER WHERE C_MKTSEGMENT=:1',
|
||||
['AUTOMOBILE']
|
||||
);
|
||||
})
|
||||
.then(function(rows) {
|
||||
console.log(rows);
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.error(err);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
main();
|
||||
44
examples/streaming.js
Normal file
44
examples/streaming.js
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// Use this when processing large datasets (or when retrieving only a few rows
|
||||
// from a large result set). This is common when doing batch processing.
|
||||
//
|
||||
// This avoids loading the entire result set into memory, and lets you work on
|
||||
// one row at a time.
|
||||
//
|
||||
|
||||
const Snowflake = require('snowflake-promise').Snowflake;
|
||||
|
||||
async function main() {
|
||||
const snowflake = new Snowflake({
|
||||
account: '<account name>',
|
||||
username: '<username>',
|
||||
password: '<password>',
|
||||
database: 'SNOWFLAKE_SAMPLE_DATA',
|
||||
schema: 'TPCH_SF1',
|
||||
warehouse: 'DEMO_WH'
|
||||
});
|
||||
|
||||
await snowflake.connect();
|
||||
|
||||
// this query returns tens of thousands of rows
|
||||
const statement = snowflake.createStatement({
|
||||
sqlText: 'SELECT * FROM CUSTOMER WHERE C_MKTSEGMENT=:1',
|
||||
binds: ['AUTOMOBILE'],
|
||||
streamResult: true
|
||||
});
|
||||
|
||||
await statement.execute();
|
||||
|
||||
// How many rows did it return? (Without loading all of them.)
|
||||
console.log(`the query result set has ${statement.getNumRows()} rows`);
|
||||
|
||||
// let’s process rows 250-275, one by one
|
||||
// (if you omit the argument for streamRows(), all rows will be processed)
|
||||
statement.streamRows({ start: 250, end: 275 })
|
||||
.on('error', console.error)
|
||||
.on('data', row => console.log(`customer name is: ${row['C_NAME']}`))
|
||||
.on('end', () => console.log('done processing'))
|
||||
;
|
||||
}
|
||||
|
||||
main();
|
||||
1920
package-lock.json
generated
Normal file
1920
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
31
package.json
Normal file
31
package.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "snowflake-promise",
|
||||
"version": "1.0.0",
|
||||
"description": "A Promise-based, TypeScript-friendly wrapper for the Snowflake SDK",
|
||||
"main": "prod/src/index.js",
|
||||
"types": "prod/src/index.d.ts",
|
||||
"scripts": {
|
||||
"prepare": "del-cli prod && tsc"
|
||||
},
|
||||
"keywords": [
|
||||
"snowflake",
|
||||
"database",
|
||||
"data warehouse",
|
||||
"warehouse"
|
||||
],
|
||||
"author": "Nate Silva <nate@natesilva.com>",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^8.0.28",
|
||||
"del-cli": "^1.1.0",
|
||||
"ts-node": "^3.3.0",
|
||||
"tslint": "^5.7.0",
|
||||
"typescript": "^2.5.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"snowflake-sdk": "^1.1.2"
|
||||
}
|
||||
}
|
||||
52
src/Snowflake.ts
Normal file
52
src/Snowflake.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import * as SDK from 'snowflake-sdk';
|
||||
|
||||
import { ConnectionOptions } from './types/ConnectionOptions';
|
||||
import { ExecuteOptions } from './types/ExecuteOptions';
|
||||
import { Statement } from './Statement';
|
||||
|
||||
export class Snowflake {
|
||||
private readonly sdk_connection;
|
||||
|
||||
/* Creates a new Snowflake instance. */
|
||||
constructor(private readonly connectionOptions: ConnectionOptions) {
|
||||
this.sdk_connection = SDK.createConnection(connectionOptions);
|
||||
}
|
||||
|
||||
/** the connection id */
|
||||
get id(): string { return this.sdk_connection.getId(); }
|
||||
|
||||
/** Establishes a connection if we aren't in a fatal state. */
|
||||
connect() {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.sdk_connection.connect(err => {
|
||||
if (err) { reject(err); }
|
||||
else { resolve(); }
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Immediately terminates the connection without waiting for currently
|
||||
* executing statements to complete.
|
||||
*/
|
||||
destroy() {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.sdk_connection.destroy(err => {
|
||||
if (err) { reject(err); }
|
||||
else { resolve(); }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** Create a Statement. */
|
||||
createStatement(options: ExecuteOptions) {
|
||||
return new Statement(this.sdk_connection, options);
|
||||
}
|
||||
|
||||
/** A convenience function to execute a SQL statement and return the resulting rows. */
|
||||
execute(sqlText: string, binds?: any[]) {
|
||||
const stmt = this.createStatement({sqlText, binds});
|
||||
stmt.execute();
|
||||
return stmt.getRows();
|
||||
}
|
||||
}
|
||||
151
src/Statement.ts
Normal file
151
src/Statement.ts
Normal file
@ -0,0 +1,151 @@
|
||||
import { ExecuteOptions } from './types/ExecuteOptions';
|
||||
import { Readable } from 'stream';
|
||||
import { Snowflake } from './Snowflake';
|
||||
import { StatementAlreadyExecutedError } from './types/StatementAlreadyExecutedError';
|
||||
import { StatementNotExecutedError } from './types/StatementNotExecutedError';
|
||||
import { StatementStreamingModeMismatchError } from './types/StatementStreamingModeMismatchError';
|
||||
import { StreamRowsOptions } from './types/StreamRowsOptions';
|
||||
|
||||
export class Statement {
|
||||
private rows: any[] = null;
|
||||
private stmt: any = null;
|
||||
private executePromise: Promise<Statement> = null;
|
||||
|
||||
/**
|
||||
* @param connection the connection object from the SDK
|
||||
* @param sqlText the SQL to execute
|
||||
* @param binds parameters to bind in the statement
|
||||
*/
|
||||
constructor(
|
||||
private readonly connection: any,
|
||||
private readonly executeOptions: ExecuteOptions
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Execute this Statement.
|
||||
* @throws if the statement was previously executed or an error occurs
|
||||
* @return Promise<void>
|
||||
*/
|
||||
execute() {
|
||||
if (this.executePromise) { throw new StatementAlreadyExecutedError(); }
|
||||
|
||||
this.executePromise = new Promise((resolve, reject) => {
|
||||
this.executeOptions['complete'] = (err, stmt, rows) => {
|
||||
if (err) { reject(err); }
|
||||
this.rows = rows;
|
||||
resolve();
|
||||
};
|
||||
|
||||
this.stmt = this.connection.execute(this.executeOptions);
|
||||
});
|
||||
|
||||
return this.executePromise;
|
||||
}
|
||||
|
||||
/** Cancel a currently-executing Statement. */
|
||||
cancel() {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.stmt.cancel(err => {
|
||||
if (err) { reject(err); }
|
||||
else { resolve(); }
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rows returned by the Statement.
|
||||
* @throws if the Statement was not in streaming mode
|
||||
*/
|
||||
getRows() {
|
||||
if (!this.executePromise) { throw new StatementNotExecutedError(); }
|
||||
|
||||
if (this.executeOptions.streamResult) {
|
||||
const msg = 'Statement is in streaming mode; cannot get rows (non-streaming)';
|
||||
throw new StatementStreamingModeMismatchError(msg);
|
||||
}
|
||||
|
||||
return this.executePromise.then(() => this.rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream the rows returned by the Statement.
|
||||
* @throws if the statement was in non-streaming mode
|
||||
*/
|
||||
streamRows(options: StreamRowsOptions = {}): Readable {
|
||||
if (!this.executePromise) { throw new StatementNotExecutedError(); }
|
||||
|
||||
if (!this.executeOptions.streamResult) {
|
||||
const msg = 'cannot stream rows from Statement in non-streaming mode';
|
||||
throw new StatementStreamingModeMismatchError(msg);
|
||||
}
|
||||
|
||||
return this.stmt.streamRows(options);
|
||||
}
|
||||
|
||||
/** this statement's SQL text */
|
||||
getSqlText(): string {
|
||||
if (!this.executePromise) { throw new StatementNotExecutedError(); }
|
||||
return this.stmt.getSqlText();
|
||||
}
|
||||
|
||||
/** the current status of this statement */
|
||||
getStatus(): string {
|
||||
if (!this.executePromise) { throw new StatementNotExecutedError(); }
|
||||
return this.stmt.getStatus();
|
||||
}
|
||||
|
||||
/** the columns produced by this statement */
|
||||
getColumns(): object[] {
|
||||
if (!this.executePromise) { throw new StatementNotExecutedError(); }
|
||||
return this.stmt.getColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a column identifier, returns the corresponding column. The column
|
||||
* identifier can be either the column name (String) or the column index
|
||||
* (Number). If a column is specified and there is more than one column with
|
||||
* that name, the first column with the specified name will be returned.
|
||||
*/
|
||||
getColumn(columnIdentifier: string | number): object {
|
||||
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(); }
|
||||
return this.stmt.getNumRows();
|
||||
}
|
||||
|
||||
/** the number of rows updated by this statement */
|
||||
getNumUpdatedRows(): number {
|
||||
if (!this.executePromise) { throw new StatementNotExecutedError(); }
|
||||
return this.stmt.getNumUpdatedRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object that contains information about the values of the
|
||||
* current warehouse, current database, etc., when this statement finished
|
||||
* executing.
|
||||
*/
|
||||
getSessionState() {
|
||||
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(); }
|
||||
return this.stmt.getRequestId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the statement id generated by the server for this statement.
|
||||
* If the statement is still executing and we don't know the statement id
|
||||
* yet, this method will return undefined.
|
||||
*/
|
||||
getStatementId(): object {
|
||||
if (!this.executePromise) { throw new StatementNotExecutedError(); }
|
||||
return this.stmt.getStatementtId();
|
||||
}
|
||||
}
|
||||
10
src/index.ts
Normal file
10
src/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export { Snowflake } from './Snowflake';
|
||||
export { Statement } from './Statement';
|
||||
|
||||
export { ConnectionOptions } from './types/ConnectionOptions';
|
||||
export { ExecuteOptions } from './types/ExecuteOptions';
|
||||
export { SnowflakeError } from './types/SnowflakeError';
|
||||
export { StatementAlreadyExecutedError } from './types/StatementAlreadyExecutedError';
|
||||
export { StatementNotExecutedError } from './types/StatementNotExecutedError';
|
||||
export { StatementStreamingModeMismatchError } from './types/StatementStreamingModeMismatchError';
|
||||
export { StreamRowsOptions } from './types/StreamRowsOptions';
|
||||
30
src/types/ConnectionOptions.ts
Normal file
30
src/types/ConnectionOptions.ts
Normal file
@ -0,0 +1,30 @@
|
||||
export interface ConnectionOptions {
|
||||
/**
|
||||
* Name of your Snowflake account as it appears in the URL for accessing the
|
||||
* web interface. For example, in https://abc123.snowflakecomputing.com,
|
||||
* abc123 is the account name.
|
||||
*/
|
||||
account: string;
|
||||
/** Snowflake user login name to connect with. */
|
||||
username: string;
|
||||
/** Password for the user. */
|
||||
password: string;
|
||||
/**
|
||||
* Region for the user. Currently, only required for users connecting to the
|
||||
* following regions:
|
||||
* US East: us-east-1
|
||||
* EU (Frankfurt): eu-central-1
|
||||
*/
|
||||
region?: string;
|
||||
/** The default database to use for the session after connecting. */
|
||||
database?: string;
|
||||
/** The default schema to use for the session after connecting. */
|
||||
schema?: string;
|
||||
/**
|
||||
* The default virtual warehouse to use for the session after connecting. Used
|
||||
* for performing queries, loading data, etc.
|
||||
*/
|
||||
warehouse?: string;
|
||||
/** The default security role to use for the session after connecting. */
|
||||
role?: string;
|
||||
}
|
||||
9
src/types/ExecuteOptions.ts
Normal file
9
src/types/ExecuteOptions.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export type FetchAsStringTypes = 'String' | 'Boolean' | 'Number' | 'Date' | 'JSON';
|
||||
|
||||
export interface ExecuteOptions {
|
||||
sqlText: string;
|
||||
binds?: any[];
|
||||
streamResult?: boolean;
|
||||
fetchAsString?: FetchAsStringTypes[];
|
||||
// note: the complete callback is not exposed; our Promise wrapper uses it internally
|
||||
}
|
||||
3
src/types/SnowflakeError.ts
Normal file
3
src/types/SnowflakeError.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export class SnowflakeError extends Error {
|
||||
constructor(message) { super(message); }
|
||||
}
|
||||
7
src/types/StatementAlreadyExecutedError.ts
Normal file
7
src/types/StatementAlreadyExecutedError.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { SnowflakeError } from './SnowflakeError';
|
||||
|
||||
export class StatementAlreadyExecutedError extends SnowflakeError {
|
||||
constructor() {
|
||||
super('Statement already executed - it cannot be executed again');
|
||||
}
|
||||
}
|
||||
7
src/types/StatementNotExecutedError.ts
Normal file
7
src/types/StatementNotExecutedError.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { SnowflakeError } from './SnowflakeError';
|
||||
|
||||
export class StatementNotExecutedError extends SnowflakeError {
|
||||
constructor() {
|
||||
super('Statement not executed yet - call the execute() method');
|
||||
}
|
||||
}
|
||||
11
src/types/StatementStreamingModeMismatchError.ts
Normal file
11
src/types/StatementStreamingModeMismatchError.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { SnowflakeError } from './SnowflakeError';
|
||||
|
||||
export class StatementStreamingModeMismatchError extends SnowflakeError {
|
||||
constructor(message) {
|
||||
super(
|
||||
message ||
|
||||
'mismatch: attempted non-streaming operation on a streaming-mode Statement, or ' +
|
||||
'attempted streaming operation on non-streaming-mode Statement'
|
||||
);
|
||||
}
|
||||
}
|
||||
4
src/types/StreamRowsOptions.ts
Normal file
4
src/types/StreamRowsOptions.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface StreamRowsOptions {
|
||||
start?: number;
|
||||
end?: number;
|
||||
}
|
||||
18
tsconfig.json
Normal file
18
tsconfig.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"include": [
|
||||
"src/**/*",
|
||||
"test/**/*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"outDir": "prod",
|
||||
"target": "ES5",
|
||||
"module": "commonjs",
|
||||
"sourceMap": true,
|
||||
"lib": ["es5", "es2015.promise"],
|
||||
"noImplicitReturns": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"pretty": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
31
tslint.json
Normal file
31
tslint.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"rules": {
|
||||
"no-unused-expression": true,
|
||||
// "no-unused-variable": [true, {"ignore-pattern": "^_"}],
|
||||
"no-duplicate-variable": true,
|
||||
"curly": true,
|
||||
"class-name": true,
|
||||
"semicolon": [
|
||||
"always"
|
||||
],
|
||||
"triple-equals": true,
|
||||
"quotemark": [
|
||||
"single"
|
||||
],
|
||||
"linebreak-style": [
|
||||
"LF"
|
||||
],
|
||||
"eofline": true,
|
||||
"no-conditional-assignment": true,
|
||||
"typeof-compare": true,
|
||||
"use-isnan": true,
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"arrow-return-shorthand": [
|
||||
true
|
||||
],
|
||||
"no-trailing-whitespace": true
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user