Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

mysql release有没有更好的写法?

$
0
0

如果先调用connection.release(),就不会走return的代码,尝试使用try/catch/finally可以实现,但是感觉不好看,connection.release()是否有更优雅的使用方法,看文档定义是这样的,When you are done with a connection, just call connection.release() and the connection will return to the pool, ready to be used again by someone else.大家平时怎么处理release的?

		let connection = await mysqlPool.getConnection();
        let comment_count = await connection.query(sql, tid);
        console.log('mysql exec.');
        let count = comment_count[0]['count'];
        
        connection.release();
        return count;

Viewing all articles
Browse latest Browse all 14821

Trending Articles