Comparing version 1.6.5 to 1.7.0
@@ -0,1 +1,14 @@ | ||
1.7.0 | ||
- Fix crashing when session info packet does not | ||
start with length-coded string #1004, #989 | ||
- build: drop node 4 and 6 and add node v12 #997 | ||
- Add support for timezone connection option #996, #15, #262, | ||
#642, #877, #888 | ||
- Make mysql2 compatible with minification #992, #890, #899, | ||
#890 | ||
- fix serialisation of '00:00:00' time #968, #967 | ||
- Allow to set minVersion ssl option #961, #960 | ||
- Fix a MaxListenersExceededWarning with stream | ||
local infile #965 | ||
1.6.5 (08/02/2019) | ||
@@ -2,0 +15,0 @@ - allow to use namedPlaceholders flag per query #879 |
12
index.js
@@ -9,12 +9,12 @@ 'use strict'; | ||
module.exports.createConnection = function(opts) { | ||
exports.createConnection = function(opts) { | ||
return new Connection({ config: new ConnectionConfig(opts) }); | ||
}; | ||
module.exports.connect = module.exports.createConnection; | ||
module.exports.Connection = Connection; | ||
exports.connect = exports.createConnection; | ||
exports.Connection = Connection; | ||
const Pool = require('./lib/pool.js'); | ||
module.exports.createPool = function(config) { | ||
exports.createPool = function(config) { | ||
const PoolConfig = require('./lib/pool_config.js'); | ||
@@ -31,5 +31,5 @@ return new Pool({ config: new PoolConfig(config) }); | ||
module.exports.Pool = Pool; | ||
exports.Pool = Pool; | ||
module.exports.createServer = function(handler) { | ||
exports.createServer = function(handler) { | ||
const Server = require('./lib/server.js'); | ||
@@ -36,0 +36,0 @@ const s = new Server(); |
@@ -66,3 +66,3 @@ 'use strict'; | ||
const stage1 = sha1(password); | ||
return module.exports.calculateTokenFromPasswordSha( | ||
return exports.calculateTokenFromPasswordSha( | ||
stage1, | ||
@@ -74,3 +74,3 @@ scramble1, | ||
module.exports.calculateTokenFromPasswordSha = function( | ||
exports.calculateTokenFromPasswordSha = function( | ||
passwordSha, | ||
@@ -85,5 +85,5 @@ scramble1, | ||
module.exports.calculateToken = token; | ||
exports.calculateToken = token; | ||
module.exports.verifyToken = function( | ||
exports.verifyToken = function( | ||
publicSeed1, | ||
@@ -96,8 +96,7 @@ publicSeed2, | ||
const candidateHash2 = sha1(hashStage1); | ||
// TODO better way to compare buffers? | ||
return candidateHash2.toString('hex') == doubleSha.toString('hex'); | ||
return candidateHash2.compare(doubleSha) === 0; | ||
}; | ||
module.exports.doubleSha1 = function(password) { | ||
exports.doubleSha1 = function(password) { | ||
return sha1(sha1(password)); | ||
}; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -154,3 +154,3 @@ 'use strict'; | ||
} | ||
if (authSwitchHandlerParams.pluginName == 'mysql_native_password') { | ||
if (authSwitchHandlerParams.pluginName === 'mysql_native_password') { | ||
const authToken = this.calculateNativePasswordAuthToken( | ||
@@ -157,0 +157,0 @@ authSwitchHandlerParams.pluginData |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -15,3 +15,3 @@ 'use strict'; | ||
for (const i in this) { | ||
if (this[i] == state && i != 'next') { | ||
if (this[i] === state && i !== 'next') { | ||
return i; | ||
@@ -43,6 +43,6 @@ } | ||
return false; | ||
} else { | ||
this.emit('end'); | ||
return true; | ||
} | ||
} | ||
this.emit('end'); | ||
return true; | ||
} | ||
@@ -49,0 +49,0 @@ } |
@@ -41,3 +41,4 @@ 'use strict'; | ||
this.parameters, | ||
connection.config.charsetNumber | ||
connection.config.charsetNumber, | ||
connection.config.timezone | ||
); | ||
@@ -72,3 +73,3 @@ //For reasons why this try-catch is here, please see | ||
this._fields[this._resultIndex].push(field); | ||
if (this._receivedFieldsCount == this._fieldCount) { | ||
if (this._receivedFieldsCount === this._fieldCount) { | ||
fields = this._fields[this._resultIndex]; | ||
@@ -75,0 +76,0 @@ this.emit('fields', fields, this._resultIndex); |
'use strict'; | ||
'client_handshake server_handshake query prepare close_statement execute ping register_slave binlog_dump change_user quit' | ||
.split(' ') | ||
.forEach(name => { | ||
const ctor = require('./' + name + '.js'); | ||
module.exports[ctor.name] = ctor; | ||
}); | ||
const ClientHandshake = require('./client_handshake.js'); | ||
const ServerHandshake = require('./server_handshake.js'); | ||
const Query = require('./query.js'); | ||
const Prepare = require('./prepare.js'); | ||
const CloseStatement = require('./close_statement.js'); | ||
const Execute = require('./execute.js'); | ||
const Ping = require('./ping.js'); | ||
const RegisterSlave = require('./register_slave.js'); | ||
const BinlogDump = require('./binlog_dump.js'); | ||
const ChangeUser = require('./change_user.js'); | ||
const Quit = require('./quit.js'); | ||
module.exports = { | ||
ClientHandshake, | ||
ServerHandshake, | ||
Query, | ||
Prepare, | ||
CloseStatement, | ||
Execute, | ||
Ping, | ||
RegisterSlave, | ||
BinlogDump, | ||
ChangeUser, | ||
Quit | ||
}; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -23,3 +23,3 @@ 'use strict'; | ||
execute(parameters, callback) { | ||
if (typeof parameters == 'function') { | ||
if (typeof parameters === 'function') { | ||
callback = parameters; | ||
@@ -72,7 +72,7 @@ parameters = []; | ||
return Prepare.prototype.readParameter; | ||
} else if (this.fieldCount > 0) { | ||
} if (this.fieldCount > 0) { | ||
return Prepare.prototype.readField; | ||
} else { | ||
return this.prepareDone(connection); | ||
} | ||
} | ||
return this.prepareDone(connection); | ||
} | ||
@@ -83,3 +83,3 @@ | ||
this.parameterDefinitions.push(def); | ||
if (this.parameterDefinitions.length == this.parameterCount) { | ||
if (this.parameterDefinitions.length === this.parameterCount) { | ||
return Prepare.prototype.parametersEOF; | ||
@@ -93,3 +93,3 @@ } | ||
this.fields.push(def); | ||
if (this.fields.length == this.fieldCount) { | ||
if (this.fields.length === this.fieldCount) { | ||
return Prepare.prototype.fieldsEOF; | ||
@@ -106,5 +106,5 @@ } | ||
return Prepare.prototype.readField; | ||
} else { | ||
return this.prepareDone(connection); | ||
} | ||
} | ||
return this.prepareDone(connection); | ||
} | ||
@@ -111,0 +111,0 @@ |
@@ -109,5 +109,3 @@ 'use strict'; | ||
console.log( | ||
' Resultset header received, expecting ' + | ||
rs.fieldCount + | ||
' column definition packets' | ||
` Resultset header received, expecting ${rs.fieldCount} column definition packets` | ||
); | ||
@@ -144,2 +142,5 @@ } | ||
_streamLocalInfile(connection) { | ||
const onConnectionError = () => { | ||
this._unpipeStream(); | ||
}; | ||
const onDrain = () => { | ||
@@ -159,2 +160,3 @@ this._localStream.resume(); | ||
const onEnd = () => { | ||
connection.removeListener('error', onConnectionError); | ||
connection.writePacket(EmptyPacket); | ||
@@ -164,2 +166,3 @@ }; | ||
this._localStreamError = err; | ||
connection.removeListener('error', onConnectionError); | ||
connection.writePacket(EmptyPacket); | ||
@@ -179,5 +182,3 @@ }; | ||
this._localStream.on('error', onError); | ||
connection.once('error', () => { | ||
this._unpipeStream(); | ||
}); | ||
connection.once('error', onConnectionError); | ||
} | ||
@@ -191,3 +192,3 @@ | ||
// this is the reason _receivedFieldsCount exist (otherwise we could just use current length of fields array) | ||
if (this._fields[this._resultIndex].length != this._fieldCount) { | ||
if (this._fields[this._resultIndex].length !== this._fieldCount) { | ||
const field = new Packets.ColumnDefinition( | ||
@@ -201,5 +202,5 @@ packet, | ||
console.log(' Column definition:'); | ||
console.log(' name: ' + field.name); | ||
console.log(' type: ' + field.columnType); | ||
console.log(' flags: ' + field.flags); | ||
console.log(` name: ${field.name}`); | ||
console.log(` type: ${field.columnType}`); | ||
console.log(` flags: ${field.flags}`); | ||
/* eslint-enable no-console */ | ||
@@ -206,0 +207,0 @@ } |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -42,32 +42,26 @@ 'use strict'; | ||
if (this.args.authCallback) { | ||
try { | ||
this.args.authCallback( | ||
{ | ||
user: clientHelloReply.user, | ||
database: clientHelloReply.database, | ||
address: connection.stream.remoteAddress, | ||
authPluginData1: this.serverHello.authPluginData1, | ||
authPluginData2: this.serverHello.authPluginData2, | ||
authToken: clientHelloReply.authToken | ||
}, | ||
(err, mysqlError) => { | ||
// if (err) | ||
if (!mysqlError) { | ||
connection.writeOk(); | ||
} else { | ||
// TODO create constants / errorToCode | ||
// 1045 = ER_ACCESS_DENIED_ERROR | ||
connection.writeError({ | ||
message: mysqlError.message || '', | ||
code: mysqlError.code || 1045 | ||
}); | ||
connection.close(); | ||
} | ||
this.args.authCallback( | ||
{ | ||
user: clientHelloReply.user, | ||
database: clientHelloReply.database, | ||
address: connection.stream.remoteAddress, | ||
authPluginData1: this.serverHello.authPluginData1, | ||
authPluginData2: this.serverHello.authPluginData2, | ||
authToken: clientHelloReply.authToken | ||
}, | ||
(err, mysqlError) => { | ||
// if (err) | ||
if (!mysqlError) { | ||
connection.writeOk(); | ||
} else { | ||
// TODO create constants / errorToCode | ||
// 1045 = ER_ACCESS_DENIED_ERROR | ||
connection.writeError({ | ||
message: mysqlError.message || '', | ||
code: mysqlError.code || 1045 | ||
}); | ||
connection.close(); | ||
} | ||
); | ||
} catch (err) { | ||
throw err; | ||
// TODO | ||
// connection.writeError(err) | ||
} | ||
} | ||
); | ||
} else { | ||
@@ -136,7 +130,5 @@ connection.writeOk(); | ||
connection.emit('packet', packet.clone(), knownCommand, commandCode); | ||
} else { | ||
if (!knownCommand) { | ||
// eslint-disable-next-line no-console | ||
console.log('Unknown command:', commandCode); | ||
} | ||
} else if (!knownCommand) { | ||
// eslint-disable-next-line no-console | ||
console.log('Unknown command:', commandCode); | ||
} | ||
@@ -143,0 +135,0 @@ return ServerHandshake.prototype.dispatchCommands; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -59,3 +59,3 @@ 'use strict'; | ||
for (const key in uriOptions) { | ||
if (!uriOptions.hasOwnProperty(key)) continue; | ||
if (!Object.prototype.hasOwnProperty.call(uriOptions, key)) continue; | ||
if (options[key]) continue; | ||
@@ -66,3 +66,3 @@ options[key] = uriOptions[key]; | ||
for (const key in options) { | ||
if (!options.hasOwnProperty(key)) continue; | ||
if (!Object.prototype.hasOwnProperty.call(options, key)) continue; | ||
if (validOptions[key] !== 1) { | ||
@@ -72,5 +72,3 @@ // REVIEW: Should this be emitted somehow? | ||
console.error( | ||
'Ignoring invalid configuration option passed to Connection: ' + | ||
key + | ||
'. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration options to a Connection' | ||
`Ignoring invalid configuration option passed to Connection: ${key}. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection` | ||
); | ||
@@ -99,3 +97,17 @@ } | ||
this.stringifyObjects = options.stringifyObjects || false; | ||
this.timezone = options.timezone || 'local'; | ||
if ( | ||
options.timezone && | ||
!/^(?:local|Z|[ +-]\d\d:\d\d)$/.test(options.timezone) | ||
) { | ||
// strictly supports timezones specified by mysqljs/mysql: | ||
// https://github.com/mysqljs/mysql#user-content-connection-options | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
`Ignoring invalid timezone passed to Connection: ${options.timezone}. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection` | ||
); | ||
// SqlStrings falls back to UTC on invalid timezone | ||
this.timezone = 'Z'; | ||
} else { | ||
this.timezone = options.timezone || 'local'; | ||
} | ||
this.queryFormat = options.queryFormat; | ||
@@ -113,7 +125,7 @@ this.pool = options.pool || undefined; | ||
this.typeCast = options.typeCast === undefined ? true : options.typeCast; | ||
if (this.timezone[0] == ' ') { | ||
if (this.timezone[0] === ' ') { | ||
// "+" is a url encoded char for space so it | ||
// gets translated to space when giving a | ||
// connection string.. | ||
this.timezone = '+' + this.timezone.substr(1); | ||
this.timezone = `+${this.timezone.substr(1)}`; | ||
} | ||
@@ -123,3 +135,3 @@ if (this.ssl) { | ||
throw new TypeError( | ||
"SSL profile must be an object, instead it's a " + typeof this.ssl | ||
`SSL profile must be an object, instead it's a ${typeof this.ssl}` | ||
); | ||
@@ -150,3 +162,3 @@ } | ||
for (i in default_flags) { | ||
if (user_flags.indexOf('-' + default_flags[i]) >= 0) { | ||
if (user_flags.indexOf(`-${default_flags[i]}`) >= 0) { | ||
continue; | ||
@@ -158,3 +170,3 @@ } | ||
for (i in user_flags) { | ||
if (user_flags[i][0] == '-') { | ||
if (user_flags[i][0] === '-') { | ||
continue; | ||
@@ -204,3 +216,3 @@ } | ||
if (num === undefined) { | ||
throw new TypeError("Unknown charset '" + charset + "'"); | ||
throw new TypeError(`Unknown charset '${charset}'`); | ||
} | ||
@@ -216,3 +228,3 @@ return num; | ||
if (ssl === undefined) { | ||
throw new TypeError("Unknown SSL profile '" + name + "'"); | ||
throw new TypeError(`Unknown SSL profile '${name}'`); | ||
} | ||
@@ -219,0 +231,0 @@ return ssl; |
@@ -40,9 +40,7 @@ 'use strict'; | ||
} | ||
// if stream is a function, treat it as "stream agent / factory" | ||
} else if (typeof opts.config.stream === 'function') { | ||
this.stream = opts.config.stream(opts); | ||
} else { | ||
// if stream is a function, treat it as "stream agent / factory" | ||
if (typeof opts.config.stream == 'function') { | ||
this.stream = opts.config.stream(opts); | ||
} else { | ||
this.stream = opts.config.stream; | ||
} | ||
this.stream = opts.config.stream; | ||
} | ||
@@ -54,3 +52,3 @@ this._internalId = _connectionId++; | ||
this._paused_packets = new Queue(); | ||
this._statements = LRU({ | ||
this._statements = new LRU({ | ||
max: this.config.maxPreparedStatements, | ||
@@ -194,15 +192,13 @@ dispose: function(key, statement) { | ||
this._command = null; | ||
} else { | ||
// connection handshake is special because we allow it to be implicit | ||
// if error happened during handshake, but there are others commands in queue | ||
// then bubble error to other commands and not to connection | ||
if ( | ||
!( | ||
this._command && | ||
this._command.constructor == Commands.ClientHandshake && | ||
this._commands.length > 0 | ||
) | ||
) { | ||
bubbleErrorToConnection = true; | ||
} | ||
} else if ( | ||
!( | ||
this._command && | ||
this._command.constructor === Commands.ClientHandshake && | ||
this._commands.length > 0 | ||
) | ||
) { | ||
bubbleErrorToConnection = true; | ||
} | ||
@@ -261,20 +257,7 @@ while ((command = this._commands.shift())) { | ||
console.log( | ||
this._internalId + | ||
' ' + | ||
this.connectionId + | ||
' <== ' + | ||
this._command._commandName + | ||
'#' + | ||
this._command.stateName() + | ||
'(' + | ||
[this.sequenceId, packet._name, packet.length()].join(',') + | ||
')' | ||
`${this._internalId} ${this.connectionId} <== ${this._command._commandName}#${this._command.stateName()}(${[this.sequenceId, packet._name, packet.length()].join(',')})` | ||
); | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
this._internalId + | ||
' ' + | ||
this.connectionId + | ||
' <== ' + | ||
packet.buffer.toString('hex') | ||
`${this._internalId} ${this.connectionId} <== ${packet.buffer.toString('hex')}` | ||
); | ||
@@ -288,19 +271,7 @@ } | ||
console.log( | ||
this._internalId + | ||
' ' + | ||
this.connectionId + | ||
' <== Writing large packet, raw content not written:' | ||
`${this._internalId} ${this.connectionId} <== Writing large packet, raw content not written:` | ||
); | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
this._internalId + | ||
' ' + | ||
this.connectionId + | ||
' <== ' + | ||
this._command._commandName + | ||
'#' + | ||
this._command.stateName() + | ||
'(' + | ||
[this.sequenceId, packet._name, packet.length()].join(',') + | ||
')' | ||
`${this._internalId} ${this.connectionId} <== ${this._command._commandName}#${this._command.stateName()}(${[this.sequenceId, packet._name, packet.length()].join(',')})` | ||
); | ||
@@ -338,3 +309,4 @@ } | ||
key: this.config.ssl.key, | ||
passphrase: this.config.ssl.passphrase | ||
passphrase: this.config.ssl.passphrase, | ||
minVersion: this.config.ssl.minVersion | ||
}); | ||
@@ -402,6 +374,3 @@ const rejectUnauthorized = this.config.ssl.rejectUnauthorized; | ||
const err = new Error( | ||
'Warning: got packets out of order. Expected ' + | ||
this.sequenceId + | ||
' but received ' + | ||
packet.sequenceId | ||
`Warning: got packets out of order. Expected ${this.sequenceId} but received ${packet.sequenceId}` | ||
); | ||
@@ -420,6 +389,5 @@ err.expected = this.sequenceId; | ||
console.log( | ||
' raw: ' + | ||
packet.buffer | ||
.slice(packet.offset, packet.offset + packet.length()) | ||
.toString('hex') | ||
` raw: ${packet.buffer | ||
.slice(packet.offset, packet.offset + packet.length()) | ||
.toString('hex')}` | ||
); | ||
@@ -436,12 +404,3 @@ // eslint-disable-next-line no-console | ||
console.log( | ||
this._internalId + | ||
' ' + | ||
this.connectionId + | ||
' ==> ' + | ||
commandName + | ||
'#' + | ||
stateName + | ||
'(' + | ||
[packet.sequenceId, packet.type(), packet.length()].join(',') + | ||
')' | ||
`${this._internalId} ${this.connectionId} ==> ${commandName}#${stateName}(${[packet.sequenceId, packet.type(), packet.length()].join(',')})` | ||
); | ||
@@ -475,3 +434,3 @@ } | ||
// eslint-disable-next-line no-console | ||
console.log('Add command: ' + commandName); | ||
console.log(`Add command: ${commandName}`); | ||
cmd._commandName = commandName; | ||
@@ -489,3 +448,3 @@ } | ||
format(sql, values) { | ||
if (typeof this.config.queryFormat == 'function') { | ||
if (typeof this.config.queryFormat === 'function') { | ||
return this.config.queryFormat.call( | ||
@@ -537,3 +496,3 @@ this, | ||
let cmdQuery; | ||
if (sql.constructor == Commands.Query) { | ||
if (sql.constructor === Commands.Query) { | ||
cmdQuery = sql; | ||
@@ -569,3 +528,3 @@ } else { | ||
prepare(options, cb) { | ||
if (typeof options == 'string') { | ||
if (typeof options === 'string') { | ||
options = { sql: options }; | ||
@@ -882,8 +841,3 @@ } | ||
return ( | ||
typeof options.nestTables + | ||
'/' + | ||
options.nestTables + | ||
'/' + | ||
options.rowsAsArray + | ||
options.sql | ||
`${typeof options.nestTables}/${options.nestTables}/${options.rowsAsArray}${options.sql}` | ||
); | ||
@@ -890,0 +844,0 @@ } |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -47,5 +47,5 @@ 'use strict'; | ||
// eslint-disable-next-line no-console | ||
console.log(highlightFn(code) + '\n'); | ||
console.log(`${highlightFn(code)}\n`); | ||
} | ||
exports.printDebugWithCode = printDebugWithCode; |
@@ -20,3 +20,3 @@ 'use strict'; | ||
// 4 for normal packets, 7 for comprssed protocol packets | ||
if (typeof packetHeaderLength == 'undefined') { | ||
if (typeof packetHeaderLength === 'undefined') { | ||
packetHeaderLength = 4; | ||
@@ -39,3 +39,3 @@ } | ||
this._flushLargePacket = | ||
packetHeaderLength == 7 | ||
packetHeaderLength === 7 | ||
? this._flushLargePacket7 | ||
@@ -113,3 +113,3 @@ : this._flushLargePacket4; | ||
this.length = chunk[start]; | ||
if (this.headerLen == 2) { | ||
if (this.headerLen === 2) { | ||
this.length = chunk[start] + (chunk[start + 1] << 8); | ||
@@ -185,5 +185,5 @@ this.execute = PacketParser.prototype.executeHeader3; | ||
return this.executePayload(chunk.slice(2)); | ||
} else { | ||
this.execute = PacketParser.prototype.executeHeader3; | ||
} | ||
} | ||
this.execute = PacketParser.prototype.executeHeader3; | ||
return null; | ||
@@ -190,0 +190,0 @@ } |
@@ -29,3 +29,3 @@ 'use strict'; | ||
static verifyMarker(packet) { | ||
return packet.peekByte() == 0x01; | ||
return packet.peekByte() === 0x01; | ||
} | ||
@@ -32,0 +32,0 @@ } |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -83,6 +83,6 @@ 'use strict'; | ||
toPacket() { | ||
if (typeof this.user != 'string') { | ||
if (typeof this.user !== 'string') { | ||
throw new Error('"user" connection config property must be a string'); | ||
} | ||
if (typeof this.database != 'string') { | ||
if (typeof this.database !== 'string') { | ||
throw new Error('"database" connection config property must be a string'); | ||
@@ -89,0 +89,0 @@ } |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -113,4 +113,4 @@ 'use strict'; | ||
get: function() { | ||
const start = this['_' + name + 'Start']; | ||
const end = start + this['_' + name + 'Length']; | ||
const start = this[`_${name}Start`]; | ||
const end = start + this[`_${name}Length`]; | ||
return StringParser.decode( | ||
@@ -117,0 +117,0 @@ this._buf.slice(start, end), |
@@ -21,3 +21,3 @@ 'use strict'; | ||
*/ | ||
function toParameter(value, encoding) { | ||
function toParameter(value, encoding, timezone) { | ||
let type = Types.VAR_STRING; | ||
@@ -48,6 +48,9 @@ let length; | ||
case 'object': | ||
if (Object.prototype.toString.call(value) == '[object Date]') { | ||
if (Object.prototype.toString.call(value) === '[object Date]') { | ||
type = Types.DATETIME; | ||
length = 12; | ||
writer = Packet.prototype.writeDate; | ||
writer = function(value) { | ||
// eslint-disable-next-line no-invalid-this | ||
return Packet.prototype.writeDate.call(this, value, timezone); | ||
}; | ||
} else if (isJSON(value)) { | ||
@@ -76,6 +79,7 @@ value = JSON.stringify(value); | ||
class Execute { | ||
constructor(id, parameters, charsetNumber) { | ||
constructor(id, parameters, charsetNumber, timezone) { | ||
this.id = id; | ||
this.parameters = parameters; | ||
this.encoding = CharsetToEncoding[charsetNumber]; | ||
this.timezone = timezone; | ||
} | ||
@@ -98,3 +102,3 @@ | ||
parameters = this.parameters.map(value => | ||
toParameter(value, this.encoding) | ||
toParameter(value, this.encoding, this.timezone) | ||
); | ||
@@ -121,3 +125,3 @@ length += parameters.reduce( | ||
bitValue *= 2; | ||
if (bitValue == 256) { | ||
if (bitValue === 256) { | ||
packet.writeInt8(bitmap); | ||
@@ -128,3 +132,3 @@ bitmap = 0; | ||
}); | ||
if (bitValue != 1) { | ||
if (bitValue !== 1) { | ||
packet.writeInt8(bitmap); | ||
@@ -131,0 +135,0 @@ } |
@@ -92,6 +92,6 @@ 'use strict'; | ||
toPacket() { | ||
if (typeof this.user != 'string') { | ||
if (typeof this.user !== 'string') { | ||
throw new Error('"user" connection config property must be a string'); | ||
} | ||
if (typeof this.database != 'string') { | ||
if (typeof this.database !== 'string') { | ||
throw new Error('"database" connection config property must be a string'); | ||
@@ -98,0 +98,0 @@ } |
@@ -0,0 +0,0 @@ 'use strict'; |
'use strict'; | ||
'auth_switch_request auth_switch_response auth_switch_request_more_data binlog_dump register_slave ssl_request handshake handshake_response query resultset_header column_definition text_row binary_row prepare_statement close_statement prepared_statement_header execute change_user' | ||
.split(' ') | ||
.forEach(name => { | ||
const ctor = require('./' + name + '.js'); | ||
module.exports[ctor.name] = ctor; | ||
// monkey-patch it to include name if debug is on | ||
if (process.env.NODE_DEBUG) { | ||
if (ctor.prototype.toPacket) { | ||
const old = ctor.prototype.toPacket; | ||
ctor.prototype.toPacket = function() { | ||
const p = old.call(this); | ||
p._name = ctor.name; | ||
return p; | ||
}; | ||
} | ||
const AuthSwitchRequest = require('./auth_switch_request'); | ||
const AuthSwitchRequestMoreData = require('./auth_switch_request_more_data'); | ||
const AuthSwitchResponse = require('./auth_switch_response'); | ||
const BinaryRow = require('./binary_row'); | ||
const BinlogDump = require('./binlog_dump'); | ||
const ChangeUser = require('./change_user'); | ||
const CloseStatement = require('./close_statement'); | ||
const ColumnDefinition = require('./column_definition'); | ||
const Execute = require('./execute'); | ||
const Handshake = require('./handshake'); | ||
const HandshakeResponse = require('./handshake_response'); | ||
const PrepareStatement = require('./prepare_statement'); | ||
const PreparedStatementHeader = require('./prepared_statement_header'); | ||
const Query = require('./query'); | ||
const RegisterSlave = require('./register_slave'); | ||
const ResultsetHeader = require('./resultset_header'); | ||
const SslRequest = require('./ssl_request'); | ||
const TextRow = require('./text_row'); | ||
const ctorArr = [ | ||
AuthSwitchRequest, | ||
AuthSwitchRequestMoreData, | ||
AuthSwitchResponse, | ||
BinaryRow, | ||
BinlogDump, | ||
ChangeUser, | ||
CloseStatement, | ||
ColumnDefinition, | ||
Execute, | ||
Handshake, | ||
HandshakeResponse, | ||
PrepareStatement, | ||
PreparedStatementHeader, | ||
Query, | ||
RegisterSlave, | ||
ResultsetHeader, | ||
SslRequest, | ||
TextRow | ||
]; | ||
ctorArr.forEach(ctor => { | ||
module.exports[ctor.name] = ctor; | ||
// monkey-patch it to include name if debug is on | ||
if (process.env.NODE_DEBUG) { | ||
if (ctor.prototype.toPacket) { | ||
const old = ctor.prototype.toPacket; | ||
ctor.prototype.toPacket = function() { | ||
const p = old.call(this); | ||
p._name = ctor.name; | ||
return p; | ||
}; | ||
} | ||
}); | ||
} | ||
}); | ||
@@ -56,6 +92,6 @@ // simple packets: | ||
static toPacket(warnings, statusFlags) { | ||
if (typeof warnings == 'undefined') { | ||
if (typeof warnings === 'undefined') { | ||
warnings = 0; | ||
} | ||
if (typeof statusFlags == 'undefined') { | ||
if (typeof statusFlags === 'undefined') { | ||
statusFlags = 0; | ||
@@ -62,0 +98,0 @@ } |
@@ -172,3 +172,3 @@ 'use strict'; | ||
isEOF() { | ||
return this.buffer[this.offset] == 0xfe && this.length() < 13; | ||
return this.buffer[this.offset] === 0xfe && this.length() < 13; | ||
} | ||
@@ -199,12 +199,12 @@ | ||
let res; | ||
if (tag == 0xfb) { | ||
if (tag === 0xfb) { | ||
return null; | ||
} | ||
if (tag == 0xfc) { | ||
if (tag === 0xfc) { | ||
return this.readInt8() + (this.readInt8() << 8); | ||
} | ||
if (tag == 0xfd) { | ||
if (tag === 0xfd) { | ||
return this.readInt8() + (this.readInt8() << 8) + (this.readInt8() << 16); | ||
} | ||
if (tag == 0xfe) { | ||
if (tag === 0xfe) { | ||
// TODO: check version | ||
@@ -229,3 +229,3 @@ // Up to MySQL 3.22, 0xfe was followed by a 4-byte integer. | ||
console.trace(); | ||
throw new Error('Should not reach here: ' + tag); | ||
throw new Error(`Should not reach here: ${tag}`); | ||
} | ||
@@ -246,3 +246,3 @@ | ||
readBuffer(len) { | ||
if (typeof len == 'undefined') { | ||
if (typeof len === 'undefined') { | ||
len = this.end - this.offset; | ||
@@ -255,34 +255,44 @@ } | ||
// DATE, DATETIME and TIMESTAMP | ||
readDateTime() { | ||
const length = this.readInt8(); | ||
if (length == 0xfb) { | ||
return null; | ||
readDateTime(timezone) { | ||
if (!timezone || timezone === 'Z' || timezone === 'local') { | ||
const length = this.readInt8(); | ||
if (length === 0xfb) { | ||
return null; | ||
} | ||
let y = 0; | ||
let m = 0; | ||
let d = 0; | ||
let H = 0; | ||
let M = 0; | ||
let S = 0; | ||
let ms = 0; | ||
if (length > 3) { | ||
y = this.readInt16(); | ||
m = this.readInt8(); | ||
d = this.readInt8(); | ||
} | ||
if (length > 6) { | ||
H = this.readInt8(); | ||
M = this.readInt8(); | ||
S = this.readInt8(); | ||
} | ||
if (length > 10) { | ||
ms = this.readInt32() / 1000; | ||
} | ||
if (y + m + d + H + M + S + ms === 0) { | ||
return INVALID_DATE; | ||
} | ||
if (timezone === 'Z') { | ||
return new Date(Date.UTC(y, m - 1, d, H, M, S, ms)); | ||
} | ||
return new Date(y, m - 1, d, H, M, S, ms); | ||
} | ||
let y = 0; | ||
let m = 0; | ||
let d = 0; | ||
let H = 0; | ||
let M = 0; | ||
let S = 0; | ||
let ms = 0; | ||
if (length > 3) { | ||
y = this.readInt16(); | ||
m = this.readInt8(); | ||
d = this.readInt8(); | ||
let str = this.readDateTimeString(6, 'T'); | ||
if (str.length === 10) { | ||
str += 'T00:00:00'; | ||
} | ||
if (length > 6) { | ||
H = this.readInt8(); | ||
M = this.readInt8(); | ||
S = this.readInt8(); | ||
} | ||
if (length > 10) { | ||
ms = this.readInt32() / 1000; | ||
} | ||
if (y + m + d + H + M + S + ms === 0) { | ||
return INVALID_DATE; | ||
} | ||
return new Date(y, m - 1, d, H, M, S, ms); | ||
return new Date(str + timezone); | ||
} | ||
readDateTimeString(decimals) { | ||
readDateTimeString(decimals, timeSep) { | ||
const length = this.readInt8(); | ||
@@ -307,3 +317,7 @@ let y = 0; | ||
S = this.readInt8(); | ||
str += ' ' + [leftPad(2, H), leftPad(2, M), leftPad(2, S)].join(':'); | ||
str += `${timeSep || ' '}${[ | ||
leftPad(2, H), | ||
leftPad(2, M), | ||
leftPad(2, S) | ||
].join(':')}`; | ||
} | ||
@@ -328,3 +342,3 @@ if (length > 10) { | ||
if (length === 0) { | ||
return 0; | ||
return '00:00:00'; | ||
} | ||
@@ -357,3 +371,3 @@ const sign = this.readInt8() ? -1 : 1; // 'isNegative' flag byte | ||
[d ? d * 24 + H : H, leftPad(2, M), leftPad(2, S)].join(':') + | ||
(ms ? '.' + ms : '') | ||
(ms ? `.${ms}` : '') | ||
); | ||
@@ -397,3 +411,3 @@ } | ||
readString(len, encoding) { | ||
if (typeof len == 'undefined') { | ||
if (typeof len === 'undefined') { | ||
len = this.end - this.offset; | ||
@@ -424,3 +438,3 @@ } | ||
} | ||
if (this.buffer[this.offset] == minus) { | ||
if (this.buffer[this.offset] === minus) { | ||
this.offset++; | ||
@@ -436,13 +450,13 @@ sign = -1; | ||
result = parseInt(str, 10); | ||
if (result.toString() == str) { | ||
if (result.toString() === str) { | ||
return sign * result; | ||
} else { | ||
return sign == -1 ? '-' + str : str; | ||
} | ||
} else if (numDigits > 16) { | ||
return sign === -1 ? `-${str}` : str; | ||
} | ||
if (numDigits > 16) { | ||
str = this.readString(end - this.offset); | ||
return sign == -1 ? '-' + str : str; | ||
return sign === -1 ? `-${str}` : str; | ||
} | ||
} | ||
if (this.buffer[this.offset] == plus) { | ||
if (this.buffer[this.offset] === plus) { | ||
this.offset++; // just ignore | ||
@@ -460,7 +474,6 @@ } | ||
str = this.buffer.toString('ascii', start, end); | ||
if (num.toString() == str) { | ||
if (num.toString() === str) { | ||
return num; | ||
} else { | ||
return str; | ||
} | ||
return str; | ||
} | ||
@@ -482,7 +495,7 @@ | ||
} | ||
if (this.buffer[this.offset] == minus) { | ||
if (this.buffer[this.offset] === minus) { | ||
this.offset++; | ||
sign = -1; | ||
} | ||
if (this.buffer[this.offset] == plus) { | ||
if (this.buffer[this.offset] === plus) { | ||
this.offset++; // just ignore | ||
@@ -591,3 +604,3 @@ } | ||
parseDate() { | ||
parseDate(timezone) { | ||
const strLen = this.readLengthCodedNumber(); | ||
@@ -597,3 +610,3 @@ if (strLen === null) { | ||
} | ||
if (strLen != 10) { | ||
if (strLen !== 10) { | ||
// we expect only YYYY-MM-DD here. | ||
@@ -608,6 +621,14 @@ // if for some reason it's not the case return invalid date | ||
const d = this.parseInt(2); | ||
return new Date(y, m - 1, d); | ||
if (!timezone || timezone === 'local') { | ||
return new Date(y, m - 1, d); | ||
} | ||
if (timezone === 'Z') { | ||
return new Date(Date.UTC(y, m - 1, d)); | ||
} | ||
return new Date( | ||
`${leftPad(4, y)}-${leftPad(2, m)}-${leftPad(2, d)}T00:00:00${timezone}` | ||
); | ||
} | ||
parseDateTime() { | ||
parseDateTime(timezone) { | ||
const str = this.readLengthCodedString('binary'); | ||
@@ -617,3 +638,6 @@ if (str === null) { | ||
} | ||
return new Date(str); | ||
if (!timezone || timezone === 'local') { | ||
return new Date(str); | ||
} | ||
return new Date(`${str}${timezone}`); | ||
} | ||
@@ -633,7 +657,7 @@ | ||
} | ||
if (this.buffer[this.offset] == minus) { | ||
if (this.buffer[this.offset] === minus) { | ||
this.offset++; | ||
factor = -1; | ||
} | ||
if (this.buffer[this.offset] == plus) { | ||
if (this.buffer[this.offset] === plus) { | ||
this.offset++; // just ignore | ||
@@ -643,6 +667,6 @@ } | ||
charCode = this.buffer[this.offset]; | ||
if (charCode == dot) { | ||
if (charCode === dot) { | ||
pastDot = true; | ||
this.offset++; | ||
} else if (charCode == exponent || charCode == exponentCapital) { | ||
} else if (charCode === exponent || charCode === exponentCapital) { | ||
this.offset++; | ||
@@ -686,7 +710,7 @@ const exponentValue = this.parseInt(end - this.offset); | ||
isAlt() { | ||
return this.peekByte() == 0xfe; | ||
return this.peekByte() === 0xfe; | ||
} | ||
isError() { | ||
return this.peekByte() == 0xff; | ||
return this.peekByte() === 0xff; | ||
} | ||
@@ -699,3 +723,3 @@ | ||
let sqlState = ''; | ||
if (this.buffer[this.offset] == 0x23) { | ||
if (this.buffer[this.offset] === 0x23) { | ||
this.skip(1); | ||
@@ -809,11 +833,30 @@ sqlState = this.readBuffer(5).toString(); | ||
writeDate(d) { | ||
writeDate(d, timezone) { | ||
this.buffer.writeUInt8(11, this.offset); | ||
this.buffer.writeUInt16LE(d.getFullYear(), this.offset + 1); | ||
this.buffer.writeUInt8(d.getMonth() + 1, this.offset + 3); | ||
this.buffer.writeUInt8(d.getDate(), this.offset + 4); | ||
this.buffer.writeUInt8(d.getHours(), this.offset + 5); | ||
this.buffer.writeUInt8(d.getMinutes(), this.offset + 6); | ||
this.buffer.writeUInt8(d.getSeconds(), this.offset + 7); | ||
this.buffer.writeUInt32LE(d.getMilliseconds() * 1000, this.offset + 8); | ||
if (!timezone || timezone === 'local') { | ||
this.buffer.writeUInt16LE(d.getFullYear(), this.offset + 1); | ||
this.buffer.writeUInt8(d.getMonth() + 1, this.offset + 3); | ||
this.buffer.writeUInt8(d.getDate(), this.offset + 4); | ||
this.buffer.writeUInt8(d.getHours(), this.offset + 5); | ||
this.buffer.writeUInt8(d.getMinutes(), this.offset + 6); | ||
this.buffer.writeUInt8(d.getSeconds(), this.offset + 7); | ||
this.buffer.writeUInt32LE(d.getMilliseconds() * 1000, this.offset + 8); | ||
} else { | ||
if (timezone !== 'Z') { | ||
const offset = | ||
(timezone[0] === '-' ? -1 : 1) * | ||
(parseInt(timezone.substring(1, 3), 10) * 60 + | ||
parseInt(timezone.substring(4), 10)); | ||
if (offset !== 0) { | ||
d = new Date(d.getTime() + 60000 * offset); | ||
} | ||
} | ||
this.buffer.writeUInt16LE(d.getUTCFullYear(), this.offset + 1); | ||
this.buffer.writeUInt8(d.getUTCMonth() + 1, this.offset + 3); | ||
this.buffer.writeUInt8(d.getUTCDate(), this.offset + 4); | ||
this.buffer.writeUInt8(d.getUTCHours(), this.offset + 5); | ||
this.buffer.writeUInt8(d.getUTCMinutes(), this.offset + 6); | ||
this.buffer.writeUInt8(d.getUTCSeconds(), this.offset + 7); | ||
this.buffer.writeUInt32LE(d.getUTCMilliseconds() * 1000, this.offset + 8); | ||
} | ||
this.offset += 12; | ||
@@ -841,3 +884,3 @@ } | ||
} | ||
if (this.buffer[this.offset] == 0) { | ||
if (this.buffer[this.offset] === 0) { | ||
return 'maybeOK'; // could be other packet types as well | ||
@@ -857,5 +900,4 @@ } | ||
return 5; | ||
} else { | ||
return 9; | ||
} | ||
return 9; | ||
} | ||
@@ -873,3 +915,3 @@ | ||
for (const op in NativeBuffer.prototype) { | ||
if (typeof res[op] == 'function') { | ||
if (typeof res[op] === 'function') { | ||
res[op] = noop; | ||
@@ -876,0 +918,0 @@ } |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -39,3 +39,5 @@ 'use strict'; | ||
if (isSet('SESSION_TRACK') && packet.offset < packet.end) { | ||
const sessionInfoTypes = require('../constants/session_track.js'); | ||
this.info = packet.readLengthCodedString(encoding); | ||
if (this.serverStatus && ServerSatusFlags.SERVER_SESSION_STATE_CHANGED) { | ||
@@ -52,3 +54,2 @@ // session change info record - see | ||
schema: null, | ||
// gtids: {}, | ||
trackStateChange: null | ||
@@ -61,14 +62,14 @@ }; | ||
stateEnd = packet.offset + len; | ||
key = packet.readLengthCodedString(encoding); | ||
if (type === 0) { | ||
if (type === sessionInfoTypes.SYSTEM_VARIABLES) { | ||
key = packet.readLengthCodedString(encoding); | ||
const val = packet.readLengthCodedString(encoding); | ||
stateChanges.systemVariables[key] = val; | ||
if (key == 'character_set_client') { | ||
if (key === 'character_set_client') { | ||
const charsetNumber = EncodingToCharset[val]; | ||
connection.config.charsetNumber = charsetNumber; | ||
} | ||
} else if (type === 1) { | ||
// TODO double check it's supposed to be the only value, not a list. | ||
} else if (type === sessionInfoTypes.SCHEMA) { | ||
key = packet.readLengthCodedString(encoding); | ||
stateChanges.schema = key; | ||
} else if (type === 2) { | ||
} else if (type === sessionInfoTypes.STATE_CHANGE) { | ||
stateChanges.trackStateChange = packet.readLengthCodedString( | ||
@@ -78,3 +79,3 @@ encoding | ||
} else { | ||
// GTIDs (type == 3) or unknown type - just skip for now | ||
// unsupported session track type. For now just ignore | ||
} | ||
@@ -99,3 +100,3 @@ packet.offset = stateEnd; | ||
let length = 4 + Packet.lengthCodedNumberLength(fieldCount); | ||
if (typeof insertId != 'undefined') { | ||
if (typeof insertId !== 'undefined') { | ||
length += Packet.lengthCodedNumberLength(insertId); | ||
@@ -107,3 +108,3 @@ } | ||
packet.writeLengthCodedNumber(fieldCount); | ||
if (typeof insertId != 'undefined') { | ||
if (typeof insertId !== 'undefined') { | ||
packet.writeLengthCodedNumber(insertId); | ||
@@ -110,0 +111,0 @@ } |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -23,3 +23,3 @@ 'use strict'; | ||
columns.forEach(val => { | ||
if (val === null || typeof val == 'undefined') { | ||
if (val === null || typeof val === 'undefined') { | ||
++length; | ||
@@ -38,3 +38,3 @@ return; | ||
} | ||
if (typeof val == 'undefined') { | ||
if (typeof val === 'undefined') { | ||
packet.writeInt8(0); | ||
@@ -41,0 +41,0 @@ return; |
@@ -18,2 +18,3 @@ 'use strict'; | ||
const bigNumberStrings = options.bigNumberStrings || config.bigNumberStrings; | ||
const timezone = options.timezone || config.timezone; | ||
const unsigned = field.flags & FieldFlags.UNSIGNED; | ||
@@ -41,5 +42,5 @@ switch (field.columnType) { | ||
if (config.dateStrings) { | ||
return 'packet.readDateTimeString(' + field.decimals + ');'; | ||
return `packet.readDateTimeString(${field.decimals});`; | ||
} | ||
return 'packet.readDateTime();'; | ||
return `packet.readDateTime('${timezone}');`; | ||
case Types.TIME: | ||
@@ -65,21 +66,15 @@ return 'packet.readTimeString()'; | ||
: 'packet.readSInt64JSNumber();'; | ||
} else { | ||
if (bigNumberStrings) { | ||
return unsigned | ||
? 'packet.readInt64String();' | ||
: 'packet.readSInt64String();'; | ||
} else { | ||
return unsigned ? 'packet.readInt64();' : 'packet.readSInt64();'; | ||
} | ||
} | ||
if (bigNumberStrings) { | ||
return unsigned | ||
? 'packet.readInt64String();' | ||
: 'packet.readSInt64String();'; | ||
} | ||
return unsigned ? 'packet.readInt64();' : 'packet.readSInt64();'; | ||
default: | ||
if (field.characterSet == Charsets.BINARY) { | ||
if (field.characterSet === Charsets.BINARY) { | ||
return 'packet.readLengthCodedBuffer();'; | ||
} else { | ||
return ( | ||
'packet.readLengthCodedString(CharsetToEncoding[fields[' + | ||
fieldNum + | ||
'].characterSet])' | ||
); | ||
} | ||
return `packet.readLengthCodedString(CharsetToEncoding[fields[${fieldNum}].characterSet])`; | ||
} | ||
@@ -102,3 +97,3 @@ } | ||
if (options.rowsAsArray) { | ||
parserFn('const result = new Array(' + fields.length + ');'); | ||
parserFn(`const result = new Array(${fields.length});`); | ||
} | ||
@@ -115,3 +110,3 @@ | ||
for (i = 0; i < resultTablesArray.length; i++) { | ||
parserFn('this[' + helpers.srcEscape(resultTablesArray[i]) + '] = {};'); | ||
parserFn(`this[${helpers.srcEscape(resultTablesArray[i])}] = {};`); | ||
} | ||
@@ -122,3 +117,3 @@ } | ||
for (i = 0; i < nullBitmapLength; ++i) { | ||
parserFn('const nullBitmaskByte' + i + ' = packet.readInt8();'); | ||
parserFn(`const nullBitmaskByte${i} = packet.readInt8();`); | ||
} | ||
@@ -134,19 +129,16 @@ | ||
fieldName = helpers.srcEscape(fields[i].name); | ||
parserFn('// ' + fieldName + ': ' + typeNames[fields[i].columnType]); | ||
parserFn(`// ${fieldName}: ${typeNames[fields[i].columnType]}`); | ||
if (typeof options.nestTables == 'string') { | ||
if (typeof options.nestTables === 'string') { | ||
tableName = helpers.srcEscape(fields[i].table); | ||
lvalue = | ||
'this[' + | ||
helpers.srcEscape( | ||
fields[i].table + options.nestTables + fields[i].name | ||
) + | ||
']'; | ||
lvalue = `this[${helpers.srcEscape( | ||
fields[i].table + options.nestTables + fields[i].name | ||
)}]`; | ||
} else if (options.nestTables === true) { | ||
tableName = helpers.srcEscape(fields[i].table); | ||
lvalue = 'this[' + tableName + '][' + fieldName + ']'; | ||
lvalue = `this[${tableName}][${fieldName}]`; | ||
} else if (options.rowsAsArray) { | ||
lvalue = 'result[' + i.toString(10) + ']'; | ||
lvalue = `result[${i.toString(10)}]`; | ||
} else { | ||
lvalue = 'this[' + helpers.srcEscape(fields[i].name) + ']'; | ||
lvalue = `this[${helpers.srcEscape(fields[i].name)}]`; | ||
} | ||
@@ -163,11 +155,9 @@ | ||
// } else { | ||
parserFn( | ||
'if (nullBitmaskByte' + nullByteIndex + ' & ' + currentFieldNullBit + ')' | ||
); | ||
parserFn(lvalue + ' = null;'); | ||
parserFn(`if (nullBitmaskByte${nullByteIndex} & ${currentFieldNullBit})`); | ||
parserFn(`${lvalue} = null;`); | ||
parserFn('else'); | ||
parserFn(lvalue + ' = ' + readCodeFor(fields[i], config, options, i)); | ||
parserFn(`${lvalue} = ${readCodeFor(fields[i], config, options, i)}`); | ||
// } | ||
currentFieldNullBit *= 2; | ||
if (currentFieldNullBit == 0x100) { | ||
if (currentFieldNullBit === 0x100) { | ||
currentFieldNullBit = 1; | ||
@@ -174,0 +164,0 @@ nullByteIndex++; |
@@ -9,19 +9,19 @@ 'use strict'; | ||
function keyFromFields(type, fields, options) { | ||
function keyFromFields(type, fields, options, config) { | ||
let res = | ||
type + | ||
'/' + | ||
typeof options.nestTables + | ||
'/' + | ||
options.nestTables + | ||
'/' + | ||
options.rowsAsArray + | ||
options.supportBigNumbers + | ||
'/' + | ||
options.bigNumberStrings + | ||
'/' + | ||
typeof options.typeCast; | ||
`${type}` + | ||
`/${typeof options.nestTables}` + | ||
`/${options.nestTables}` + | ||
`/${options.rowsAsArray}` + | ||
`/${options.supportBigNumbers || config.supportBigNumbers}` + | ||
`/${options.bigNumberStrings || config.bigNumberStrings}` + | ||
`/${typeof options.typeCast}` + | ||
`/${options.timezone || config.timezone}` + | ||
`/${options.decimalNumbers}` + | ||
`/${options.dateStrings}`; | ||
for (let i = 0; i < fields.length; ++i) { | ||
res += | ||
'/' + fields[i].name + ':' + fields[i].columnType + ':' + fields[i].flags; | ||
const field = fields[i]; | ||
res += `/${field.name}:${field.columnType}:${field.flags}:${ | ||
field.characterSet | ||
}`; | ||
} | ||
@@ -32,3 +32,3 @@ return res; | ||
function getParser(type, fields, options, config, compiler) { | ||
const key = keyFromFields(type, fields, options); | ||
const key = keyFromFields(type, fields, options, config); | ||
let parser = parserCache.get(key); | ||
@@ -35,0 +35,0 @@ |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -18,2 +18,3 @@ 'use strict'; | ||
const bigNumberStrings = options.bigNumberStrings || config.bigNumberStrings; | ||
const timezone = options.timezone || config.timezone; | ||
@@ -31,3 +32,3 @@ switch (type) { | ||
} | ||
return 'packet.parseLengthCodedInt(' + supportBigNumbers + ')'; | ||
return `packet.parseLengthCodedInt(${supportBigNumbers})`; | ||
case Types.FLOAT: | ||
@@ -48,3 +49,3 @@ case Types.DOUBLE: | ||
} | ||
return 'packet.parseDate()'; | ||
return `packet.parseDate('${timezone}')`; | ||
case Types.DATETIME: | ||
@@ -55,3 +56,3 @@ case Types.TIMESTAMP: | ||
} | ||
return 'packet.parseDateTime()'; | ||
return `packet.parseDateTime('${timezone}')`; | ||
case Types.TIME: | ||
@@ -67,7 +68,6 @@ return 'packet.readLengthCodedString("ascii")'; | ||
default: | ||
if (charset == Charsets.BINARY) { | ||
if (charset === Charsets.BINARY) { | ||
return 'packet.readLengthCodedBuffer()'; | ||
} else { | ||
return 'packet.readLengthCodedString(' + encodingExpr + ')'; | ||
} | ||
return `packet.readLengthCodedString(${encodingExpr})`; | ||
} | ||
@@ -117,7 +117,7 @@ } | ||
if (options.rowsAsArray) { | ||
parserFn('const result = new Array(' + fields.length + ')'); | ||
parserFn(`const result = new Array(${fields.length})`); | ||
} | ||
if (typeof options.typeCast === 'function') { | ||
parserFn('const wrap = ' + wrap.toString()); | ||
parserFn(`const wrap = ${wrap.toString()}`); | ||
} | ||
@@ -134,3 +134,3 @@ | ||
for (i = 0; i < resultTablesArray.length; i++) { | ||
parserFn('this[' + helpers.srcEscape(resultTablesArray[i]) + '] = {};'); | ||
parserFn(`this[${helpers.srcEscape(resultTablesArray[i])}] = {};`); | ||
} | ||
@@ -143,19 +143,15 @@ } | ||
fieldName = helpers.srcEscape(fields[i].name); | ||
parserFn('// ' + fieldName + ': ' + typeNames[fields[i].columnType]); | ||
if (typeof options.nestTables == 'string') { | ||
lvalue = | ||
'this[' + | ||
helpers.srcEscape( | ||
fields[i].table + options.nestTables + fields[i].name | ||
) + | ||
']'; | ||
parserFn(`// ${fieldName}: ${typeNames[fields[i].columnType]}`); | ||
if (typeof options.nestTables === 'string') { | ||
lvalue = `this[${helpers.srcEscape( | ||
fields[i].table + options.nestTables + fields[i].name | ||
)}]`; | ||
} else if (options.nestTables === true) { | ||
lvalue = | ||
'this[' + helpers.srcEscape(fields[i].table) + '][' + fieldName + ']'; | ||
lvalue = `this[${helpers.srcEscape(fields[i].table)}][${fieldName}]`; | ||
} else if (options.rowsAsArray) { | ||
lvalue = 'result[' + i.toString(10) + ']'; | ||
lvalue = `result[${i.toString(10)}]`; | ||
} else { | ||
lvalue = 'this[' + fieldName + ']'; | ||
lvalue = `this[${fieldName}]`; | ||
} | ||
const encodingExpr = 'CharsetToEncoding[fields[' + i + '].characterSet]'; | ||
const encodingExpr = `CharsetToEncoding[fields[${i}].characterSet]`; | ||
const readCode = readCodeFor( | ||
@@ -170,17 +166,10 @@ fields[i].columnType, | ||
parserFn( | ||
lvalue + | ||
' = options.typeCast(wrap(fields[' + | ||
i + | ||
'], ' + | ||
helpers.srcEscape(typeNames[fields[i].columnType]) + | ||
', packet, ' + | ||
encodingExpr + | ||
'), function() { return ' + | ||
readCode + | ||
';})' | ||
`${lvalue} = options.typeCast(wrap(fields[${i}], ${helpers.srcEscape( | ||
typeNames[fields[i].columnType] | ||
)}, packet, ${encodingExpr}), function() { return ${readCode};})` | ||
); | ||
} else if (options.typeCast === false) { | ||
parserFn(lvalue + ' = packet.readLengthCodedBuffer();'); | ||
parserFn(`${lvalue} = packet.readLengthCodedBuffer();`); | ||
} else { | ||
parserFn(lvalue + ' = ' + readCode + ';'); | ||
parserFn(`${lvalue} = ${readCode};`); | ||
} | ||
@@ -187,0 +176,0 @@ } |
@@ -93,3 +93,3 @@ 'use strict'; | ||
config = id; | ||
id = 'CLUSTER::' + ++this._lastId; | ||
id = `CLUSTER::${++this._lastId}`; | ||
} | ||
@@ -140,3 +140,3 @@ if (typeof this._nodes[id] === 'undefined') { | ||
foundNodeIds = this._serviceableNodeIds; | ||
} else if (this._serviceableNodeIds.indexOf(pattern) != -1) { | ||
} else if (this._serviceableNodeIds.indexOf(pattern) !== -1) { | ||
// one | ||
@@ -148,3 +148,3 @@ foundNodeIds = [pattern]; | ||
foundNodeIds = this._serviceableNodeIds.filter( | ||
id => id.indexOf(keyword) === 0 | ||
id => id.startsWith(keyword) | ||
); | ||
@@ -187,10 +187,10 @@ } | ||
// eslint-disable-next-line no-console | ||
console.warn('[Error] PoolCluster : ' + err); | ||
console.warn(`[Error] PoolCluster : ${err}`); | ||
return cb(null, 'retry'); | ||
} else { | ||
return cb(err); | ||
} | ||
} else { | ||
this._decreaseErrorCount(node); | ||
} | ||
} | ||
return cb(err); | ||
} | ||
this._decreaseErrorCount(node); | ||
connection._clusterId = node.id; | ||
@@ -197,0 +197,0 @@ return cb(null, connection); |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -98,3 +98,3 @@ 'use strict'; | ||
this._closed = true; | ||
if (typeof cb != 'function') { | ||
if (typeof cb !== 'function') { | ||
cb = function(err) { | ||
@@ -156,3 +156,3 @@ if (err) { | ||
// so that polymorphic arguments logic is there in one place | ||
if (typeof values == 'function') { | ||
if (typeof values === 'function') { | ||
cb = values; | ||
@@ -159,0 +159,0 @@ values = []; |
@@ -13,5 +13,5 @@ 'use strict'; | ||
(stream = new Readable(options)), | ||
(stream._read = function() { | ||
connectionStream.resume(); | ||
}); | ||
(stream._read = function() { | ||
connectionStream.resume(); | ||
}); | ||
@@ -18,0 +18,0 @@ this.on('result', (row, i) => { |
@@ -0,0 +0,0 @@ 'use strict'; |
{ | ||
"name": "mysql2", | ||
"version": "1.6.5", | ||
"version": "1.7.0", | ||
"description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS", | ||
@@ -43,3 +43,3 @@ "main": "index.js", | ||
"engines": { | ||
"node": ">= 6.0" | ||
"node": ">= 8.0" | ||
}, | ||
@@ -49,7 +49,7 @@ "author": "Andrey Sidorov <sidorares@yandex.ru>", | ||
"dependencies": { | ||
"denque": "^1.4.0", | ||
"denque": "^1.4.1", | ||
"generate-function": "^2.3.1", | ||
"iconv-lite": "^0.4.24", | ||
"iconv-lite": "^0.5.0", | ||
"long": "^4.0.0", | ||
"lru-cache": "^4.1.3", | ||
"lru-cache": "^5.1.1", | ||
"named-placeholders": "^1.1.2", | ||
@@ -61,15 +61,14 @@ "seq-queue": "^0.0.5", | ||
"assert-diff": "^2.0.2", | ||
"error-stack-parser": "^2.0.2", | ||
"eslint": "^5.8.0", | ||
"eslint-config-prettier": "^3.0.0", | ||
"error-stack-parser": "^2.0.3", | ||
"eslint": "^6.2.2", | ||
"eslint-config-prettier": "^6.1.0", | ||
"eslint-plugin-async-await": "0.0.0", | ||
"eslint-plugin-markdown": "^1.0.0-rc.0", | ||
"eslint-plugin-prettier": "^3.0.0", | ||
"husky": "^1.1.3", | ||
"eslint-plugin-markdown": "^1.0.0", | ||
"husky": "^3.0.4", | ||
"is-async-supported": "^1.2.0", | ||
"lint-staged": "^8.0.5", | ||
"portfinder": "^1.0.19", | ||
"prettier": "^1.14.3", | ||
"lint-staged": "^9.2.5", | ||
"portfinder": "^1.0.23", | ||
"prettier": "^1.18.2", | ||
"prettier-markdown": "^0.1.6", | ||
"progress": "2.0.1", | ||
"progress": "^2.0.3", | ||
"urun": "0.0.8", | ||
@@ -76,0 +75,0 @@ "utest": "0.0.8" |
@@ -219,2 +219,10 @@ 'use strict'; | ||
} | ||
get config() { | ||
return this.connection.config; | ||
} | ||
get threadId() { | ||
return this.connection.threadId; | ||
} | ||
} | ||
@@ -398,10 +406,10 @@ | ||
module.exports.createConnection = createConnection; | ||
module.exports.createPool = createPool; | ||
module.exports.escape = core.escape; | ||
module.exports.escapeId = core.escapeId; | ||
module.exports.format = core.format; | ||
module.exports.raw = core.raw; | ||
module.exports.PromisePool = PromisePool; | ||
module.exports.PromiseConnection = PromiseConnection; | ||
module.exports.PromisePoolConnection = PromisePoolConnection; | ||
exports.createConnection = createConnection; | ||
exports.createPool = createPool; | ||
exports.escape = core.escape; | ||
exports.escapeId = core.escapeId; | ||
exports.format = core.format; | ||
exports.raw = core.raw; | ||
exports.PromisePool = PromisePool; | ||
exports.PromiseConnection = PromiseConnection; | ||
exports.PromisePoolConnection = PromisePoolConnection; |
@@ -205,17 +205,14 @@ ## Node MySQL 2 | ||
```js | ||
async function main() { | ||
// get the client | ||
const mysql = require('mysql2'); | ||
// create the connection | ||
mysql.createConnection( | ||
{host:'localhost', user: 'root', database: 'test'}, | ||
(err,con) => { | ||
con.promise().query("SELECT 1") | ||
.then( ([rows,fields]) => { | ||
console.log(rows); | ||
}) | ||
.catch(console.log) | ||
.then( () => con.end()); | ||
} | ||
); | ||
// get the client | ||
const mysql = require('mysql2'); | ||
// create the connection | ||
const con = mysql.createConnection( | ||
{host:'localhost', user: 'root', database: 'test'} | ||
); | ||
con.promise().query("SELECT 1") | ||
.then( ([rows,fields]) => { | ||
console.log(rows); | ||
}) | ||
.catch(console.log) | ||
.then( () => con.end()); | ||
``` | ||
@@ -222,0 +219,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
15
68
9052
2
352156
256
+ Addediconv-lite@0.5.2(transitive)
+ Addedlru-cache@5.1.1(transitive)
+ Addedyallist@3.1.1(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedyallist@2.1.2(transitive)
Updateddenque@^1.4.1
Updatediconv-lite@^0.5.0
Updatedlru-cache@^5.1.1