查找返回的mysql结果中的行数(nodejs)

当使用felixge的mysql作为node.js时,我怎样才能得到结果对象的返回行数呢? 我有一个相当昂贵的查询,所以我不想先运行COUNT(*) ,然后再运行一个查询。

如果它是一个select查询,只需要返回数组的长度。

 connection.query(sql, [var1,var2], function(err, results) { numRows = results.length; }); 

如果是更新/删除查询,则返回的字典将具有affectedRowsvariables。

 connection.query(sql, [var1,var2], function(err, result) { numRows = result.affectedRows; }); 

如果您在自述文件中使用示例,只需查看行对象的length属性(即rows.length)即可。

使用2015-04-13版本的mssql 2.1.2:

从DeviceAccountLinks中删除,其中DeviceAccountId = @deviceAccountId和DeviceType = @deviceType

语句不会产生结果,因为“未定义”

我已经改变了声明:

从DeviceAccountLinks中删除,其中DeviceAccountId = @deviceAccountId和DeviceType = @deviceType; select@@ rowcount“rowCount”

得到的输出:[{rowCount:1}]