Node-mysql连接中的多个查询
我在我的项目中使用node-mysql。 我有一个场景,第二个查询的执行将基于从第一个返回的结果。 例如,首先查询select * from table where user = x; 然后基于存在,我将运行另一个查询。 我正在使用pool.getConnection()。 我可以知道我应该创build两个连接还是使用一个连接?
选项a)
pool.getConnection(function(err, connection) { // Use the connection connection.query( 'SELECT something FROM sometable', function(err, rows) { //store the result here as a var a; connection.release(); }); }); //check var a and start another connection to run the second query?
选项b)
pool.getConnection(function(err, connection) { // Use the connection connection.query( 'SELECT something FROM sometable', function(err, rows) { //...based on the result, connection.query(second query) connection.release(); }); });
感谢锤子
两个选项都使用一个池,所以你已经使用了多个连接。 所以任何一个选项并不重要,唯一的区别可能是第一个选项可能导致第二个查询不能马上执行,如果整个池在第一个查询完成后被使用。
- Node.js / jade – 我如何将mysql数据作为本地variables传递给内联javascript?
- mysql用户authentication为nodeftpd
- AWS Lambda不执行node.js MySQL查询
- Node.js和jdbc:TypeError:无法读取未定义的属性“url”
- NOVICE:使用HTML,CSS,AngularJS,NodeJS,MySQL的Web应用程序?
- 与同一连接的节点的mysql池连接获取并释放增加每个调用
- 使用len和setter将Sequelize密码validation失败
- 添加整数来创build条目后,ERR_EMPTY_RESPONSE node.js
- 如何使node.js和mysql一起工作?