cube.js mssql driver 问题

目前mssql driver 运行的时候会有以下错误
The multi-part identifier "columns.data_type" could not be bound

原因

需要指定别名

解决方法

MSSqlDriver 重写informationSchemaQuery 方法,我已经pr了

  • informationSchemaQuery 方法
informationSchemaQuery() {
    const q = `SELECT columns.column_name as ${this.quoteIdentifier('column_name')},
    columns.table_name as ${this.quoteIdentifier('table_name')},
    columns.table_schema as ${this.quoteIdentifier('table_schema')},
    columns.data_type as ${this.quoteIdentifier('data_type')}
FROM information_schema.columns  columns
WHERE columns.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')`;
    console.log(q);
    return q;
  }

参考源码

因为官方暂时还没有进行合并,如果需要测试mssql可以使用我已经提交的一个npm包

  • 参考使用

.env 配置
这个和官方文档一样 https://cube.dev/docs/reference/environment-variables
cube.js 文件

 
const {MSSqlDriver,MssqlQuery} = require("@dalongrong/mymssql-driver")
module.exports = {
    dialectFactory: (dataSource) => {
        // need config  datasource  for multitenant env
        return MssqlQuery
    },
    dbType: ({ dataSource } = {}) => {
        return "mymssql"
    },
    driverFactory: ({ dataSource } = {}) => {
        return new MSSqlDriver({})
    }
};

说明

npm 包名称@dalongrong/mymssql-driver 已经发布npm 官方了,可以直接使用

参考资料

https://github.com/tediousjs/node-mssql#readme
https://github.com/cube-js/cube.js/pull/2521
https://cube.dev/docs/reference/environment-variables

posted on 2021-04-09 17:01  荣锋亮  阅读(89)  评论(0编辑  收藏  举报

导航