44 * @fileoverview The `SnowflakeDriver` and related types declaration.
55 */
66
7- import {
8- getEnv ,
9- assertDataSource ,
10- } from '@cubejs-backend/shared' ;
7+ import { assertDataSource , getEnv , } from '@cubejs-backend/shared' ;
118import snowflake , { Column , Connection , RowStatement } from 'snowflake-sdk' ;
129import {
1310 BaseDriver ,
11+ DownloadQueryResultsOptions ,
12+ DownloadQueryResultsResult ,
1413 DownloadTableCSVData ,
14+ DownloadTableMemoryData ,
15+ DriverCapabilities ,
1516 DriverInterface ,
1617 GenericDataBaseType ,
17- TableStructure ,
18- UnloadOptions ,
1918 StreamOptions ,
2019 StreamTableDataWithTypes ,
21- DownloadTableMemoryData ,
22- DownloadQueryResultsResult ,
23- DownloadQueryResultsOptions ,
24- DriverCapabilities ,
20+ TableStructure ,
21+ UnloadOptions ,
2522} from '@cubejs-backend/base-driver' ;
2623import { formatToTimeZone } from 'date-fns-timezone' ;
2724import fs from 'fs/promises' ;
@@ -198,9 +195,12 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
198195 return 8 ;
199196 }
200197
198+ /**
199+ * Returns the configurable driver options
200+ * Note: It returns the unprefixed option names.
201+ * In case of using multisources options need to be prefixed manually.
202+ */
201203 public static driverEnvVariables ( ) {
202- // TODO (buntarb): check how this method can/must be used with split
203- // names by the data source.
204204 return [
205205 'CUBEJS_DB_NAME' ,
206206 'CUBEJS_DB_USER' ,
@@ -211,9 +211,11 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
211211 'CUBEJS_DB_SNOWFLAKE_ROLE' ,
212212 'CUBEJS_DB_SNOWFLAKE_CLIENT_SESSION_KEEP_ALIVE' ,
213213 'CUBEJS_DB_SNOWFLAKE_AUTHENTICATOR' ,
214+ 'CUBEJS_DB_SNOWFLAKE_OAUTH_TOKEN_PATH' ,
215+ 'CUBEJS_DB_SNOWFLAKE_HOST' ,
216+ 'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY' ,
214217 'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY_PATH' ,
215218 'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY_PASS' ,
216- 'CUBEJS_DB_SNOWFLAKE_OAUTH_TOKEN_PATH' ,
217219 'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIERS_IGNORE_CASE' ,
218220 ] ;
219221 }
@@ -257,10 +259,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
257259 privateKey += '\n' ;
258260 }
259261
260- snowflake . configure ( {
261- // TODO: Remove after release of https://github.com/snowflakedb/snowflake-connector-nodejs/pull/912
262- logLevel : 'OFF' as any
263- } ) ;
262+ snowflake . configure ( { logLevel : 'OFF' } ) ;
264263
265264 this . config = {
266265 readOnly : false ,
@@ -416,9 +415,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
416415 this . config . token = await this . readOAuthToken ( ) ;
417416 }
418417
419- const connection = snowflake . createConnection ( this . config ) ;
420-
421- return connection ;
418+ return snowflake . createConnection ( this . config ) ;
422419 }
423420
424421 /**
@@ -475,8 +472,8 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
475472 }
476473 }
477474
478- // eslint-disable-next-line no-return-assign
479- return this . connection = this . initConnection ( ) ;
475+ this . connection = this . initConnection ( ) ;
476+ return this . connection ;
480477 }
481478
482479 /**
@@ -758,7 +755,7 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
758755 const hydrationMap = this . generateHydrationMap ( stmt . getColumns ( ) ) ;
759756 const types : { name : string , type : string } [ ] =
760757 this . getTypes ( stmt ) ;
761- if ( rows && rows . length && Object . keys ( hydrationMap ) . length ) {
758+ if ( rows ? .length && Object . keys ( hydrationMap ) . length ) {
762759 for ( const row of rows ) {
763760 for ( const [ field , toValue ] of Object . entries ( hydrationMap ) ) {
764761 if ( row . hasOwnProperty ( field ) ) {
@@ -922,6 +919,6 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
922919
923920 public async getTablesQuery ( schemaName : string ) {
924921 const tables = await super . getTablesQuery ( schemaName . toUpperCase ( ) ) ;
925- return tables . map ( t => ( { table_name : t . TABLE_NAME && t . TABLE_NAME . toLowerCase ( ) } ) ) ;
922+ return tables . map ( t => ( { table_name : t . TABLE_NAME ? .toLowerCase ( ) } ) ) ;
926923 }
927924}
0 commit comments