mysql2
Advanced tools
Comparing version 3.9.3 to 3.9.4
@@ -15,5 +15,8 @@ 'use strict'; | ||
function readCodeFor(field, config, options, fieldNum) { | ||
const supportBigNumbers = | ||
options.supportBigNumbers || config.supportBigNumbers; | ||
const bigNumberStrings = options.bigNumberStrings || config.bigNumberStrings; | ||
const supportBigNumbers = Boolean( | ||
options.supportBigNumbers || config.supportBigNumbers, | ||
); | ||
const bigNumberStrings = Boolean( | ||
options.bigNumberStrings || config.bigNumberStrings, | ||
); | ||
const timezone = options.timezone || config.timezone; | ||
@@ -123,3 +126,9 @@ const dateStrings = options.dateStrings || config.dateStrings; | ||
} else { | ||
parserFn('const result = {};'); | ||
parserFn('const result = Object.create(null);'); | ||
parserFn(`Object.defineProperty(result, "constructor", { | ||
value: Object.create(null), | ||
writable: false, | ||
configurable: false, | ||
enumerable: false | ||
});`); | ||
} | ||
@@ -156,3 +165,5 @@ | ||
tableName = helpers.srcEscape(fields[i].table); | ||
parserFn(`if (!result[${tableName}]) result[${tableName}] = {};`); | ||
parserFn( | ||
`if (!result[${tableName}]) result[${tableName}] = Object.create(null);`, | ||
); | ||
lvalue = `result[${tableName}][${fieldName}]`; | ||
@@ -159,0 +170,0 @@ } else if (options.rowsAsArray) { |
@@ -15,5 +15,8 @@ 'use strict'; | ||
function readCodeFor(type, charset, encodingExpr, config, options) { | ||
const supportBigNumbers = | ||
options.supportBigNumbers || config.supportBigNumbers; | ||
const bigNumberStrings = options.bigNumberStrings || config.bigNumberStrings; | ||
const supportBigNumbers = Boolean( | ||
options.supportBigNumbers || config.supportBigNumbers, | ||
); | ||
const bigNumberStrings = Boolean( | ||
options.bigNumberStrings || config.bigNumberStrings, | ||
); | ||
const timezone = options.timezone || config.timezone; | ||
@@ -89,3 +92,3 @@ const dateStrings = options.dateStrings || config.dateStrings; | ||
name: field.name, | ||
string: function(encoding = field.encoding) { | ||
string: function (encoding = field.encoding) { | ||
if (field.columnType === Types.JSON && encoding === field.encoding) { | ||
@@ -95,3 +98,5 @@ // Since for JSON columns mysql always returns charset 63 (BINARY), | ||
// see https://github.com/sidorares/node-mysql2/issues/1661 | ||
console.warn(`typeCast: JSON column "${field.name}" is interpreted as BINARY by default, recommended to manually set utf8 encoding: \`field.string("utf8")\``); | ||
console.warn( | ||
`typeCast: JSON column "${field.name}" is interpreted as BINARY by default, recommended to manually set utf8 encoding: \`field.string("utf8")\``, | ||
); | ||
} | ||
@@ -101,8 +106,8 @@ | ||
}, | ||
buffer: function() { | ||
buffer: function () { | ||
return _this.packet.readLengthCodedBuffer(); | ||
}, | ||
geometry: function() { | ||
geometry: function () { | ||
return _this.packet.parseGeometryValue(); | ||
} | ||
}, | ||
}; | ||
@@ -113,8 +118,3 @@ } | ||
/* eslint-disable no-trailing-spaces */ | ||
/* eslint-disable no-spaced-func */ | ||
/* eslint-disable no-unexpected-multiline */ | ||
parserFn('(function () {')( | ||
'return class TextRow {' | ||
); | ||
parserFn('(function () {')('return class TextRow {'); | ||
@@ -135,7 +135,13 @@ // constructor method | ||
parserFn('next(packet, fields, options) {'); | ||
parserFn("this.packet = packet;"); | ||
parserFn('this.packet = packet;'); | ||
if (options.rowsAsArray) { | ||
parserFn(`const result = new Array(${fields.length});`); | ||
} else { | ||
parserFn("const result = {};"); | ||
parserFn('const result = Object.create(null);'); | ||
parserFn(`Object.defineProperty(result, "constructor", { | ||
value: Object.create(null), | ||
writable: false, | ||
configurable: false, | ||
enumerable: false | ||
});`); | ||
} | ||
@@ -147,8 +153,10 @@ | ||
if (options.nestTables === true) { | ||
for (let i=0; i < fields.length; i++) { | ||
for (let i = 0; i < fields.length; i++) { | ||
resultTables[fields[i].table] = 1; | ||
} | ||
resultTablesArray = Object.keys(resultTables); | ||
for (let i=0; i < resultTablesArray.length; i++) { | ||
parserFn(`result[${helpers.srcEscape(resultTablesArray[i])}] = {};`); | ||
for (let i = 0; i < resultTablesArray.length; i++) { | ||
parserFn( | ||
`result[${helpers.srcEscape(resultTablesArray[i])}] = Object.create(null);`, | ||
); | ||
} | ||
@@ -164,3 +172,3 @@ } | ||
lvalue = `result[${helpers.srcEscape( | ||
fields[i].table + options.nestTables + fields[i].name | ||
fields[i].table + options.nestTables + fields[i].name, | ||
)}]`; | ||
@@ -183,7 +191,9 @@ } else if (options.nestTables === true) { | ||
config, | ||
options | ||
options, | ||
); | ||
if (typeof options.typeCast === 'function') { | ||
parserFn(`${lvalue} = options.typeCast(this.wrap${i}, function() { return ${readCode} });`); | ||
} else { | ||
parserFn( | ||
`${lvalue} = options.typeCast(this.wrap${i}, function() { return ${readCode} });`, | ||
); | ||
} else { | ||
parserFn(`${lvalue} = ${readCode};`); | ||
@@ -198,14 +208,10 @@ } | ||
/* eslint-enable no-trailing-spaces */ | ||
/* eslint-enable no-spaced-func */ | ||
/* eslint-enable no-unexpected-multiline */ | ||
if (config.debug) { | ||
helpers.printDebugWithCode( | ||
'Compiled text protocol row parser', | ||
parserFn.toString() | ||
parserFn.toString(), | ||
); | ||
} | ||
if (typeof options.typeCast === 'function') { | ||
return parserFn.toFunction({wrap}); | ||
return parserFn.toFunction({ wrap }); | ||
} | ||
@@ -212,0 +218,0 @@ return parserFn.toFunction(); |
{ | ||
"name": "mysql2", | ||
"version": "3.9.3", | ||
"version": "3.9.4", | ||
"description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS", | ||
@@ -16,3 +16,3 @@ "main": "index.js", | ||
"test:tsc-build": "cd \"test/tsc-build\" && npx tsc -p \"tsconfig.json\"", | ||
"coverage-test": "c8 -r cobertura -r lcov -r text npm run test", | ||
"coverage-test": "c8 npm run test", | ||
"benchmark": "node ./benchmarks/benchmark.js", | ||
@@ -19,0 +19,0 @@ "prettier": "prettier --single-quote --trailing-comma none --write \"{lib,test}/**/*.js\"", |
Sorry, the diff of this file is too big to display
709541
16574
6