node-mysql何时返回“ fields”作为查询结果的一部分

时间:2019-01-28 04:09:34

标签: node.js node-mysql

根据node-mysql documentation,查询的回调将获得三个参数-错误,查询的行或结果以及称为fields的东西,可能不是每次都通过。

  

字段将包含有关返回结果字段的信息(如果有的话)

我最近遇到了一个错误,该错误是由于节点mysql在生产环境中而不是在登台环境中返回fields而导致的。我正在使用async.auto,并将步骤回调直接传递给mysql.query。在生产中,async.autorowsfields组合成一个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
  //       }
  //     ]
  //   ]
  // ]
});

0 个答案:

没有答案