Understanding "fields" returned by Node.js MySQL query

98 views Asked by At

I've got a Node.js MySQL set up like this:

db.query("SELECT * FROM build_stat",
    function (err, result, fields) {
        if (err) { throw err; }
        fields.forEach(elem => {
            console.log(elem);
        })
        response.json({
            "result": result,
            "fields": fields
        });
    }
);

In the command line, fields prints objects like this. I believe this is "Column Definition".

{
  catalog: "def",
  schema: "builds_stats",
  name: "recipe_name",
  orgName: "recipe_name",
  table: "recipes",
  orgTable: "recipes",
  characterSet: 224,
  encoding: "utf8",
  columnLength: 400,
  type: 253,
  flags: [ "NOT NULL" ],
  decimals: 0,
  typeName: "VAR_STRING"
}

But when I get it into JavaScript, the object has changed:

{
    _buf: {
        type: "Buffer",
        data: Array(14600)
    },
    _clientEncoding: "utf8",
    _catalogLength: 3,
    _catalogStart: 3846,
    _schemaLength: 12,
    _schemaStart: 3850,
    _tableLength: 7,
    _tableStart: 3863,
    _orgTableLength: 7,
    _orgTableStart: 3871,
    _orgNameLength: 11,
    _orgNameStart: 3891,
    characterSet: 224,
    encoding: "utf8",
    name: "recipe_name",
    columnLength: 400,
    columnType: 253,
    type: 253,
    flags: 4097,
    decimals: 0
}

Why does it change? How do I preserve/regain the original object?

For example, presumably flags: [ "NOT NULL" ] corresponds to flags: 4097, but how do I parse 4097 back into something meaningful?

0

There are 0 answers