@@ -163,6 +163,8 @@ interface SnowflakeDriverOptions {
163163 executionTimeout ?: number ,
164164 identIgnoreCase ?: boolean ,
165165 application : string ,
166+ snowflakeExecutionProcedure ?: string ,
167+ snowflakeInformationSchemaProcedure ?: string ,
166168 readOnly ?: boolean ,
167169
168170 /**
@@ -208,6 +210,8 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
208210 'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY_PATH' ,
209211 'CUBEJS_DB_SNOWFLAKE_PRIVATE_KEY_PASS' ,
210212 'CUBEJS_DB_SNOWFLAKE_QUOTED_IDENTIFIERS_IGNORE_CASE' ,
213+ 'CUBEJS_DB_SNOWFLAKE_EXECUTION_PROCEDURE' ,
214+ 'CUBEJS_DB_SNOWFLAKE_INFORMATION_SCHEMA_PROCEDURE' ,
211215 ] ;
212216 }
213217
@@ -296,6 +300,8 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
296300 identIgnoreCase : getEnv ( 'snowflakeQuotedIdentIgnoreCase' , { dataSource } ) ,
297301 exportBucketCsvEscapeSymbol : getEnv ( 'dbExportBucketCsvEscapeSymbol' , { dataSource } ) ,
298302 application : 'CubeDev_Cube' ,
303+ snowflakeExecutionProcedure : getEnv ( 'snowflakeExecutionProcedure' , { dataSource } ) ,
304+ snowflakeInformationSchemaProcedure : getEnv ( 'snowflakeInformationSchemaProcedure' , { dataSource } ) ,
299305 ...config
300306 } ;
301307 }
@@ -879,6 +885,24 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
879885 values ?: unknown [ ] ,
880886 rehydrate : boolean = true
881887 ) : Promise < R > {
888+ if (
889+ this . config . snowflakeExecutionProcedure &&
890+ query . toUpperCase ( ) . startsWith ( 'SELECT' )
891+ ) {
892+ const escapedQuery = query . replace ( / ' / g, "\\'" ) ;
893+ const serializedBinds = `ARRAY_CONSTRUCT(${ ( values ?? [ ] )
894+ . map ( ( v ) =>
895+ typeof v === 'string'
896+ ? `'${ String ( v ) . replace ( / ' / g, "''" ) } '`
897+ : v === null || v === undefined
898+ ? "NULL"
899+ : v
900+ )
901+ . join ( ", " ) } )`;
902+
903+ query = `CALL ${ this . config . snowflakeExecutionProcedure } ('${ escapedQuery } ', ${ serializedBinds } )` ;
904+ }
905+
882906 return new Promise ( ( resolve , reject ) => connection . execute ( {
883907 sqlText : query ,
884908 binds : < string [ ] | undefined > values ,
@@ -908,6 +932,15 @@ export class SnowflakeDriver extends BaseDriver implements DriverInterface {
908932 }
909933
910934 public informationSchemaQuery ( ) {
935+ if ( this . config . snowflakeInformationSchemaProcedure ) {
936+ return `
937+ SELECT COLUMN_NAME as "column_name",
938+ TABLE_NAME as "table_name",
939+ TABLE_SCHEMA as "table_schema",
940+ DATA_TYPE as "data_type"
941+ FROM TABLE(${ this . config . snowflakeInformationSchemaProcedure } ())` ;
942+ }
943+
911944 return `
912945 SELECT COLUMNS.COLUMN_NAME as "column_name",
913946 COLUMNS.TABLE_NAME as "table_name",
0 commit comments