Skip to content

Can driver_factory return Custom Driver instances and Driver Config Objects?Β #8962

@matheusb-comp

Description

@matheusb-comp

Problem

From the driver_factory documentation, when using JavaScript, there are examples for returning a driver config object ({ type: "duckdb" }) and an instance of a Custom Driver (class that extends BaseDriver).

However, I'm getting an error with the option configured to return both formats:

driverFactory: ({ dataSource }) => {
  if (dataSource === "mySource") {
    return new MyCustomDriver();
  } else {
    return { type: "duckdb" };
  }
}

From the TypeScript definition this should be OK, but this is the error that happens during schema compilation:

Compiling schema error: e25ceb53-6fa6-4128-bdc9-a0cc1d92728c-span-1 (289ms)
{
  "version": "default_schema_version_69b10a3ae4ba76ea6144b864e4d001d1"
} 
Error: CreateOptions.driverFactory function must return either BaseDriver or DriverConfig.
    at OptsHandler.assertDriverFactoryResult (/cube/node_modules/@cubejs-backend/server-core/src/core/OptsHandler.ts:146:15)
    at /cube/node_modules/@cubejs-backend/server-core/src/core/OptsHandler.ts:225:21
    at CubejsServerCore.contextToDbType (/cube/node_modules/@cubejs-backend/server-core/src/core/OptsHandler.ts:246:17)
    at CompilerApi.dbType (/cube/node_modules/@cubejs-backend/server-core/src/core/server.ts:499:28)

If instead I return a driver instance, no error is shown:

// const CubejsServerCore = require('@cubejs-backend/server-core');
driverFactory: ({ dataSource }) => {
  if (dataSource === "mySource") {
    return new MyCustomDriver();
  } else {
    return CubejsServerCore.createDriver("duckdb");
  }
}

Metadata

Metadata

Assignees

Labels

questionThe issue is a question. Please use Stack Overflow for questions.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions