无法读取未定义的属性“省略格式”
Posted
技术标签:
【中文标题】无法读取未定义的属性“省略格式”【英文标题】:Cannot read property 'omitFormat' of undefined 【发布时间】:2019-11-19 12:08:26 【问题描述】:我在clickhouse
中创建了一个表格,如下所示:
let clickhouse = new ClickHouse (sails.config.clickhouse);
let query = `CREATE TABLE table1(category String,subcategory String,title String,id Int64) Engine=Log`
我尝试这样运行上面的查询:
return new Promise((resolve, reject) =>
clickhouse.query (query, function (err, result)
if (err)
console.log(err);
resolve('success');
);
);
let test = await createTable();
但后来我得到了这个错误:
无法读取未定义的属性“omitFormat”
这个错误有什么解决办法吗?谢谢
P.S:我尝试在 Clickhouse
客户端中运行查询,它可以工作。
【问题讨论】:
这是一个 nodejs 错误。检查驱动程序文档。可能对于创建语句应该是另一个调用await ch.querying("CREATE DATABASE test")
github.com/apla/node-clickhouse
【参考方案1】:
你传递未初始化的sails.config.clickhouse-param.
将未定义的options 传递给ClickHouse-constructor 会导致此line 中的错误。
查看控制台查看相关警告:
> You must provide at least host name to query ClickHouse // <---- !!!
>
> Error: TypeError: Cannot read property 'omitFormat' of undefined
> at ClickHouse.query (/home/runner/node_modules/@apla/clickhouse/src/clickhouse.js:257:60)
> at Promise (evalmachine.<anonymous>:8:26)
> at new Promise (<anonymous>)
> at createTable (evalmachine.<anonymous>:7:10)
> at evalmachine.<anonymous>:17:1
> at Script.runInContext (vm.js:133:20)
> at Object.runInContext (vm.js:311:6)
> at evaluate (/run_dir/repl.js:133:14)
> at ReadStream.<anonymous> (/run_dir/repl.js:116:5)
> at ReadStream.emit (events.js:198:13)
重现此错误的代码(请参阅https://repl.it/repls/FakePortlyExponent):
const ClickHouse = require('@apla/clickhouse')
let clickhouse = new ClickHouse (/*sails.config.clickhouse*/null); // <----- !!!
let query = `CREATE TABLE table1(category String,subcategory String,title String,id Int64) Engine=Log`;
async function createTable()
return new Promise((resolve, reject) =>
clickhouse.query (query, function (err, result)
if (err)
console.log(err);
resolve('success');
);
);
createTable()
.then(() =>
console.info('Success.');
)
.catch(err =>
console.error('Error:', err);
);
【讨论】:
以上是关于无法读取未定义的属性“省略格式”的主要内容,如果未能解决你的问题,请参考以下文章
带有 Ionic 4 的 SQLite?无法读取未定义类型错误的属性“then”:无法读取未定义的属性“then”
NextJS:未捕获的类型错误:无法读取未定义的属性(读取“属性”)