Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
matheusb-comp opened this issue Nov 15, 2024 · 2 comments
Assignees
Labels
question The issue is a question. Please use Stack Overflow for questions.

Comments

@matheusb-comp
Copy link

matheusb-comp commented Nov 15, 2024

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");
  }
}
@matheusb-comp matheusb-comp added the question The issue is a question. Please use Stack Overflow for questions. label Nov 15, 2024
@igorlukanin
Copy link
Member

Hi @matheusb-comp 👋

Thanks for posting! It looks like the error message has pointed you in the right direction and you were able to configure what you want. What is the question here?

@igorlukanin igorlukanin self-assigned this Nov 18, 2024
@matheusb-comp
Copy link
Author

Well, from the from typescript I understood that driver_factory could return class instances and config objects.
However, from the tests it seems it can only return one or the other, not both formats.

So the question is basically if this is the intended behaviour.
And if so, I'm not sure if CubejsServerCore.createDriver is the correct way to create the non-custom driver instances (to be equivalent to the other format, returning the config objects).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question The issue is a question. Please use Stack Overflow for questions.
Projects
None yet
Development

No branches or pull requests

2 participants