根据node-mysql documentation,查询的回调将获得三个参数-错误,查询的行或结果以及称为fields
的东西,可能不是每次都通过。
字段将包含有关返回结果字段的信息(如果有的话)
我最近遇到了一个错误,该错误是由于节点mysql在生产环境中而不是在登台环境中返回fields
而导致的。我正在使用async.auto
,并将步骤回调直接传递给mysql.query
。在生产中,async.auto
将rows
和fields
组合成一个arguments
数组,这导致该服务的那一部分崩溃,因为它以意外的格式获取了数据。>
我无法使暂存环境将fields
传递给回调,并且当我在本地尝试时,我无法使mysql
不传递fields
。有什么办法知道fields
何时传递mysql.query
,何时不传递?
本质上
async.auto({
runQuery: (next) => {
mysql.query(sql, values, next);
}
},
(err, results) => {
// if `fields` is not passed to the callback by mysql.query,
// then results.runQuery will be a row, or an array of rows -
// [
// [
// [
// {
// "columnValue": 1
// }
// ],
// [
// {
// "columnValue": 1
// }
// ]
// ]
//
// instead, if `fields` is passed to the callback by mysql.query,
// then results.queryQuery will be an array containing the row(s)
// and the fields
//
// [
// [
// [
// {
// "columnValue": 1
// }
// ],
// [
// {
// "columnValue": 1
// }
// ]
// ],
// [
// [
// {
// "catalog": "def",
// "db": "",
// "table": "",
// "orgTable": "",
// "name": "columnValue",
// "orgName": "",
// "charsetNr": 63,
// "length": 21,
// "type": 8,
// "flags": 129,
// "decimals": 0,
// "zeroFill": false,
// "protocol41": true
// }
// ],
// [
// {
// "catalog": "def",
// "db": "",
// "table": "",
// "orgTable": "",
// "name": "columnValue",
// "orgName": "",
// "charsetNr": 63,
// "length": 21,
// "type": 8,
// "flags": 129,
// "decimals": 0,
// "zeroFill": false,
// "protocol41": true
// }
// ]
// ]
// ]
});