cube.js 0.30.30 配置的一些变动

2022/7/14 6:20:16

本文主要是介绍cube.js 0.30.30 配置的一些变动,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

好久没关注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



这篇关于cube.js 0.30.30 配置的一些变动的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程