@@ -172,6 +172,8 @@ class CubejsServerCore {
172
172
options = options || { } ;
173
173
options = {
174
174
driverFactory : ( ) => CubejsServerCore . createDriver ( options . dbType ) ,
175
+ dialectFactory : ( ) => CubejsServerCore . lookupDriverClass ( options . dbType ) . dialectClass &&
176
+ CubejsServerCore . lookupDriverClass ( options . dbType ) . dialectClass ( ) ,
175
177
apiSecret : process . env . CUBEJS_API_SECRET ,
176
178
dbType : process . env . CUBEJS_DB_TYPE ,
177
179
devServer : process . env . NODE_ENV !== 'production' ,
@@ -188,6 +190,8 @@ class CubejsServerCore {
188
190
this . options = options ;
189
191
this . driverFactory = options . driverFactory ;
190
192
this . externalDriverFactory = options . externalDriverFactory ;
193
+ this . dialectFactory = options . dialectFactory ;
194
+ this . externalDialectFactory = options . externalDialectFactory ;
191
195
this . apiSecret = options . apiSecret ;
192
196
this . schemaPath = options . schemaPath || process . env . CUBEJS_SCHEMA_PATH || 'schema' ;
193
197
this . dbType = options . dbType ;
@@ -419,6 +423,9 @@ class CubejsServerCore {
419
423
this . repositoryFactory ( context ) , {
420
424
dbType : ( dataSourceContext ) => this . contextToDbType ( { ...context , ...dataSourceContext } ) ,
421
425
externalDbType : this . contextToExternalDbType ( context ) ,
426
+ dialectClass : ( dataSourceContext ) => this . dialectFactory &&
427
+ this . dialectFactory ( { ...context , ...dataSourceContext } ) ,
428
+ externalDialectClass : this . externalDialectFactory && this . externalDialectFactory ( context ) ,
422
429
schemaVersion : currentSchemaVersion ,
423
430
preAggregationsSchema : this . preAggregationsSchema ( context ) ,
424
431
context
@@ -477,7 +484,9 @@ class CubejsServerCore {
477
484
externalDbType : options . externalDbType ,
478
485
preAggregationsSchema : options . preAggregationsSchema ,
479
486
allowUngroupedWithoutPrimaryKey : this . options . allowUngroupedWithoutPrimaryKey ,
480
- compileContext : options . context
487
+ compileContext : options . context ,
488
+ dialectClass : options . dialectClass ,
489
+ externalDialectClass : options . externalDialectClass ,
481
490
} ) ;
482
491
}
483
492
@@ -506,15 +515,21 @@ class CubejsServerCore {
506
515
507
516
static createDriver ( dbType ) {
508
517
checkEnvForPlaceholders ( ) ;
518
+ return new ( CubejsServerCore . lookupDriverClass ( dbType ) ) ( ) ;
519
+ }
520
+
521
+ static lookupDriverClass ( dbType ) {
509
522
// eslint-disable-next-line global-require,import/no-dynamic-require
510
- return new ( require ( CubejsServerCore . driverDependencies ( dbType || process . env . CUBEJS_DB_TYPE ) ) ) ( ) ;
523
+ return require ( CubejsServerCore . driverDependencies ( dbType || process . env . CUBEJS_DB_TYPE ) ) ;
511
524
}
512
525
513
526
static driverDependencies ( dbType ) {
514
- if ( ! DriverDependencies [ dbType ] ) {
515
- throw new Error ( `Unsupported db type: ${ dbType } ` ) ;
527
+ if ( DriverDependencies [ dbType ] ) {
528
+ return DriverDependencies [ dbType ] ;
529
+ } else if ( fs . existsSync ( path . join ( 'node_modules' , `${ dbType } -cubejs-driver` ) ) ) {
530
+ return `${ dbType } -cubejs-driver` ;
516
531
}
517
- return DriverDependencies [ dbType ] ;
532
+ throw new Error ( `Unsupported db type: ${ dbType } ` ) ;
518
533
}
519
534
520
535
testConnections ( ) {
0 commit comments