brianc / node-pg-pool

A connection pool for node-postgres
MIT License
180 stars 64 forks source link

How to make a synchronous query? #44

Closed haalgamu closed 7 years ago

haalgamu commented 7 years ago

I am trying to create a method for a synchronous query. I'm using pg-pool and asyncawait, but I throw the following error: "Error: await functions, yield functions, and value-returning suspendable functions may only be called from within a suspendable function."

The code is:

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;
charmander commented 7 years ago

Synchronous queries aren’t supported. Hacks exist, however.