我正在尝试为同步查询创建一种方法。我正在使用 pg-pool 和 asyncawait,但我抛出以下错误:“错误:等待函数、yield 函数和返回值的可暂停函数只能从可暂停函数中调用。”
代码是:
CustomPool = function(condigDB){
this.pool = new Pool(cofigDB)
};
CustomPool.prototype.querySync = function(sql){
var result = {rows:[]};
try{
result = await(this.pool.query(sql));
}
catch(_e_){
Log.exception(_e_);
}
return result.rows;
};
module.exports = CustomPool;