好久没关注cube.js 最近0.30.30 有一个比较大的变动就是driverFactory
driverFactory: (context: DriverContext) => DriverConfig | BaseDriver | Promise<BaseDriver>;
此配置会对于开发的自定义驱动有一些影响,推荐的是自己开发的driver 也添加一个type 的定义
const PostgresDriver = require('@cubejs-backend/postgres-driver');
module.exports = {
driverFactory: ({ dataSource }) =>
new PostgresDriver({ database: dataSource }),
dbType: ({ dataSource }) => 'postgres',
};
一个参考dremio 的driver, 详细源码参考github
constructor(config = {}) {
super();
// for cube.js latest version, if we write one custome driver should add this
this.type="mydremio";
this.config = {
host: config.host || process.env.CUBEJS_DB_HOST || 'localhost',
port: config.port || process.env.CUBEJS_DB_PORT || 9047,
user: config.user || process.env.CUBEJS_DB_USER,
password: config.password || process.env.CUBEJS_DB_PASS,
database: config.database || process.env.CUBEJS_DB_NAME,
ssl: config.ssl || process.env.CUBEJS_DB_SSL,
...config,
pollTimeout: (config.pollTimeout || getEnv('dbPollTimeout') || getEnv('dbQueryTimeout')) * 1000,
pollMaxInterval: (config.pollMaxInterval || getEnv('dbPollMaxInterval')) * 1000,
};
const protocol = (this.config.ssl === true || this.config.ssl === 'true') ? 'https' : 'http';
this.config.url = `${protocol}://${this.config.host}:${this.config.port}`;
}
新版本的cube.js 对于调度也有依一些调整了,默认是共享的,如果需要,自定义可以扩展
module.exports = {
contextToAppId: ({ securityContext }) =>
`CUBEJS_APP_${securityContext.tenantId}`,
contextToOrchestratorId: ({ securityContext }) =>
`CUBEJS_APP_${securityContext.tenantId}`,
};
新版本变动还是不少的,值得深入学习研究下(目前测试,性能提升也是不少, 推荐开发自定义driver 严格使用-cubejs-driver
https://cube.dev/docs/config#options-reference-driver-factory
https://github.com/rongfengliang/cubejs-dremio-driver.git