开发一个 cube.js oceanbase driver

cube.js 去年提供了一个独立的包,方便driver 的开发,尽管oceanbase 是mysql 兼容的,但是在使用一个链接池工具的时候有些问题
所以独立包装了一个oceanbase 的driver

开发说明

基于了官方的mysql driver 对于链接池部分进行了调整,同时进行了重新命名,方便需要维护,具体代码可以参考github
同时注意官方对于三方driver 是不能按照官方仓库模式加载的,需要同时提供query 实现,这点不是很好,自己的实现就需要
做不少配置处理(详细参考下边使用示例)

参考使用

  • cube.js 文件
 
const {OceanBaseQuery,OceanBaseDriver} = require("oceanbase-cubejs-driver")
module.exports = {
    dialectFactory: (dataSource) => {
        // need config  datasource  for multitenant env
        return OceanBaseQuery
    },
    dbType: ({ dataSource } = {}) => {
        return "oceanbase"
    },
    driverFactory: ({ dataSource } = {}) => {
        return new OceanBaseDriver({
            host: xxxxxx,
            port:xxxx,
            database: xxxx,
            user:xxx,
            password: xxxx
        })
    }
};

说明

后边如果时间方便,会尝试合并到cube 官方仓库中,基于独立模式有好处也有坏处,好处是维护方便,坏处是后续进行维护需要与官方发版一致,同时npm 包我已经发布到npm 官方仓库了大家可以直接使用

参考资料

https://github.com/rongfengliang/cubejs-oceanbase-driver
https://cube.dev/docs/config

posted on 2023-02-26 22:40  荣锋亮  阅读(51)  评论(0编辑  收藏  举报

导航