diff --git a/.eslintrc b/.eslintrc index 15a9bcb7d0..49520a7f79 100644 --- a/.eslintrc +++ b/.eslintrc @@ -14,7 +14,12 @@ "node": true }, "rules": { + "no-invalid-this": "error", + "consistent-this": "error", + "prefer-arrow-callback": "error", "prefer-const": "error", + "arrow-parens": ["error", "as-needed"], + "arrow-body-style": ["error", "as-needed"], "no-var": "error", "no-use-before-define": "error", "strict": ["error", "global"] diff --git a/benchmarks/FB/hello.js b/benchmarks/FB/hello.js index 975eaa0c15..35dfcee32d 100644 --- a/benchmarks/FB/hello.js +++ b/benchmarks/FB/hello.js @@ -9,7 +9,7 @@ if (cluster.isMaster) { cluster.fork(); } - cluster.on('exit', function(worker) { + cluster.on('exit', worker => { console.log('worker ' + worker.pid + ' died'); }); @@ -58,7 +58,7 @@ function getRandomNumber() { } function sequelizeQuery(callback) { - World.findById(getRandomNumber(), function(err, world) { + World.findById(getRandomNumber(), (err, world) => { callback(null, world); }); } @@ -71,7 +71,7 @@ function handlePrepared(req, res) { mysql2conn.execute( 'SELECT * FROM world WHERE id = ?', [getRandomNumber()], - function(err, rows) { + (err, rows) => { results.push(rows[0]); if (results.length == queries) res.end(JSON.stringify(results)); } @@ -89,7 +89,7 @@ function handleMysqlIsh(conn, req, res) { mysql2conn.query( 'SELECT * FROM world WHERE id = ?', [getRandomNumber()], - function(err, rows) { + (err, rows) => { results.push(rows[0]); if (results.length == queries) res.end(JSON.stringify(results)); } @@ -103,10 +103,10 @@ function handleMysqlIshPool(pool, req, res) { const queries = values.query.queries || 1; const results = []; for (let i = 0; i < queries; ++i) { - pool.getConnection(function() { + pool.getConnection(() => { mysql2conn.query( 'SELECT * FROM world WHERE id = ' + getRandomNumber(), - function(err, rows) { + (err, rows) => { results.push(rows[0]); if (results.length == queries) res.end(JSON.stringify(results)); } @@ -122,8 +122,8 @@ function handleMaria(req, res) { for (let i = 0; i < queries; ++i) { mariaconn .query('SELECT * FROM world WHERE id = :id', { id: getRandomNumber() }) - .on('result', function(dbres) { - dbres.on('row', function(row) { + .on('result', dbres => { + dbres.on('row', row => { results.push(row); if (results.length == queries) res.end(JSON.stringify(results)); }); @@ -137,7 +137,7 @@ function sortFortunes(a, b) { function fortuneMysql(conn, res) { res.writeHead(200, { 'Content-Type': 'text/html' }); - conn.query('select * from Fortune', function(err, fortunes) { + conn.query('select * from Fortune', (err, fortunes) => { fortunes.push({ id: 0, message: 'Additional fortune added at request time.' @@ -150,11 +150,11 @@ function fortuneMysql(conn, res) { function fortuneMaria(res) { const fortunes = []; res.writeHead(200, { 'Content-Type': 'text/html' }); - mariaconn.query('SELECT * from Fortune').on('result', function(dbres) { - dbres.on('row', function(row) { + mariaconn.query('SELECT * from Fortune').on('result', dbres => { + dbres.on('row', row => { fortunes.push(row); }); - dbres.on('end', function() { + dbres.on('end', () => { fortunes.push({ id: 0, message: 'Additional fortune added at request time.' @@ -166,7 +166,7 @@ function fortuneMaria(res) { } http - .createServer(function(req, res) { + .createServer((req, res) => { // JSON response object const hello = { message: 'Hello, world' }; @@ -197,7 +197,7 @@ http res.writeHead(200, { 'Content-Type': 'application/json' }); - async.parallel(queryFunctions, function(err, results) { + async.parallel(queryFunctions, (err, results) => { res.end(JSON.stringify(results)); }); break; @@ -208,12 +208,12 @@ http function libmysqlQuery2(callback) { libmysql.query( 'SELECT * FROM world WHERE id = ' + getRandomNumber(), - function(err, res) { + (err, res) => { if (err) { throw err; } - res.fetchAll(function(err, rows) { + res.fetchAll((err, rows) => { if (err) { throw err; } @@ -232,7 +232,7 @@ http for (let i = 0; i < queries; i += 1) { queryFunctions[i] = libmysqlQuery2; } - async.parallel(queryFunctions, function(err, results) { + async.parallel(queryFunctions, (err, results) => { if (err) { res.writeHead(500); return res.end('MYSQL CONNECTION ERROR.'); @@ -279,12 +279,12 @@ http function libmysqlQuery(callback) { libmysql.query( 'SELECT * FROM world WHERE id = ' + getRandomNumber(), - function(err, res) { + (err, res) => { if (err) { throw err; } - res.fetchAll(function(err, rows) { + res.fetchAll((err, rows) => { if (err) { throw err; } @@ -297,7 +297,7 @@ http rows[0].randomNumber + ' WHERE id = ' + rows[0]['id'], - function(err) { + err => { if (err) { throw err; } @@ -316,7 +316,7 @@ http for (let i = 0; i < queries; i += 1) { queryFunctions[i] = libmysqlQuery; } - async.parallel(queryFunctions, function(err, results) { + async.parallel(queryFunctions, (err, results) => { if (err) { res.writeHead(500); return res.end('MYSQL CONNECTION ERROR.'); diff --git a/benchmarks/bench-fake-server-maria.js b/benchmarks/bench-fake-server-maria.js index 6fa4e90912..94c4b2780b 100644 --- a/benchmarks/bench-fake-server-maria.js +++ b/benchmarks/bench-fake-server-maria.js @@ -15,16 +15,16 @@ connection.connect({ function benchmarkSelect(numLeft, callback) { let numRows = 0; const q = connection.query('select 1+1 as qqq'); - q.on('result', function(res) { + q.on('result', res => { //console.log("result!"); //console.log(res); - res.on('row', function() { + res.on('row', () => { //console.log(r); numRows++; }); - res.on('end', function() { + res.on('end', () => { if (numLeft > 1) benchmarkSelect(numLeft - 1, callback); else callback(numRows); }); @@ -34,7 +34,7 @@ function benchmarkSelect(numLeft, callback) { function benchmarkSelects(n, cb) { const numSelects = 100; const start = process.hrtime(); - benchmarkSelect(numSelects, function(rowsPerQuery) { + benchmarkSelect(numSelects, rowsPerQuery => { const end = process.hrtime(); const diff = common.hrdiff(start, end); console.log( @@ -52,7 +52,7 @@ function benchmarkSelects(n, cb) { module.exports = function(done) { console.log('connected'); const testStart = process.hrtime(); - benchmarkSelects(5, function() { + benchmarkSelects(5, () => { const testEnd = process.hrtime(); console.log('total time: ', common.hrdiff(testStart, testEnd) / 1e9); connection.end(); diff --git a/benchmarks/bench-fake-server.js b/benchmarks/bench-fake-server.js index e30213c47b..969627de6a 100644 --- a/benchmarks/bench-fake-server.js +++ b/benchmarks/bench-fake-server.js @@ -23,10 +23,10 @@ function benchmarkSelect(numLeft, callback) { let rows = 0; const q = connection.query('query from fake server fixture'); - q.on('result', function() { + q.on('result', () => { rows++; }); - q.on('end', function() { + q.on('end', () => { if (numLeft > 1) benchmarkSelect(numLeft - 1, callback); else callback(rows); }); @@ -35,7 +35,7 @@ function benchmarkSelect(numLeft, callback) { function benchmarkSelects(n, cb) { const numSelects = 100000; const start = process.hrtime(); - benchmarkSelect(numSelects, function(rowsPerQuery) { + benchmarkSelect(numSelects, rowsPerQuery => { const end = process.hrtime(); const diff = common.hrdiff(start, end); console.log( @@ -52,7 +52,7 @@ function benchmarkSelects(n, cb) { module.exports = function(done) { const testStart = process.hrtime(); - benchmarkSelects(5, function() { + benchmarkSelects(5, () => { const testEnd = process.hrtime(); console.log('total time: ', common.hrdiff(testStart, testEnd) / 1e9); connection.end(); diff --git a/benchmarks/bench-insert-select-parallel.js b/benchmarks/bench-insert-select-parallel.js index 5f9c0cdeba..c42b735fef 100644 --- a/benchmarks/bench-insert-select-parallel.js +++ b/benchmarks/bench-insert-select-parallel.js @@ -6,7 +6,7 @@ const connection = common.createConnection(); const table = 'insert_test'; //const text = "本日は晴天なり"; const text = 'test abc xyz'; -connection.query('drop table ' + table).on('error', function() {}); +connection.query('drop table ' + table).on('error', () => {}); connection.query( [ 'CREATE TABLE `' + table + '` (', @@ -20,7 +20,7 @@ connection.query( function benchmarkInsert(numLeft, callback) { connection.query( 'INSERT INTO ' + table + ' SET title="' + text + '"', - function(err) { + err => { if (err) throw err; if (numLeft > 1) benchmarkInsert(numLeft - 1, callback); else callback(); @@ -31,7 +31,7 @@ function benchmarkInsert(numLeft, callback) { function benchmarkInserts(n, cb) { const numInsert = 50000; const start = process.hrtime(); - benchmarkInsert(numInsert, function() { + benchmarkInsert(numInsert, () => { const end = process.hrtime(); const diff = common.hrdiff(start, end); console.log((numInsert * 1e9) / diff + ' inserts/sec'); @@ -75,8 +75,8 @@ function benchmarkParallelSelects(n, size, cb) { module.exports = function(done) { const testStart = process.hrtime(); - benchmarkInserts(1, function() { - benchmarkParallelSelects(8, 50000, function() { + benchmarkInserts(1, () => { + benchmarkParallelSelects(8, 50000, () => { const testEnd = process.hrtime(); console.log('total time: ', common.hrdiff(testStart, testEnd) / 1e9); if (done) done(); diff --git a/benchmarks/bench-insert-select-prepared.js b/benchmarks/bench-insert-select-prepared.js index 971a6530b3..b9737999ba 100644 --- a/benchmarks/bench-insert-select-prepared.js +++ b/benchmarks/bench-insert-select-prepared.js @@ -20,7 +20,7 @@ function benchmarkInsert(numLeft, callback) { connection.execute( 'INSERT INTO ' + table + ' SET title="' + text + '"', [], - function(err) { + err => { if (err) throw err; if (numLeft > 1) benchmarkInsert(numLeft - 1, callback); else callback(); @@ -31,7 +31,7 @@ function benchmarkInsert(numLeft, callback) { function benchmarkInserts(n, cb) { const numInsert = 10000; const start = process.hrtime(); - benchmarkInsert(numInsert, function() { + benchmarkInsert(numInsert, () => { const end = process.hrtime(); const diff = common.hrdiff(start, end); console.log((numInsert * 1e9) / diff + ' inserts/sec'); @@ -44,7 +44,7 @@ function benchmarkSelect(numLeft, numSelect, callback) { connection.execute( 'select * from ' + table + ' limit ' + numSelect, [], - function(err) { + err => { if (err) throw err; if (numLeft > 1) benchmarkSelect(numLeft - 1, numSelect, callback); else callback(); @@ -55,7 +55,7 @@ function benchmarkSelect(numLeft, numSelect, callback) { function benchmarkSelects(n, size, cb) { const numSelects = 100; const start = process.hrtime(); - benchmarkSelect(numSelects, size, function() { + benchmarkSelect(numSelects, size, () => { const end = process.hrtime(); const diff = common.hrdiff(start, end); console.log( @@ -73,10 +73,10 @@ function benchmarkSelects(n, size, cb) { module.exports = function(done) { const testStart = process.hrtime(); - benchmarkInserts(1, function() { - benchmarkSelects(5, 100, function() { - benchmarkSelects(10, 1000, function() { - benchmarkSelects(2, 50000, function() { + benchmarkInserts(1, () => { + benchmarkSelects(5, 100, () => { + benchmarkSelects(10, 1000, () => { + benchmarkSelects(2, 50000, () => { const testEnd = process.hrtime(); console.log('total time: ', common.hrdiff(testStart, testEnd) / 1e9); connection.end(); diff --git a/benchmarks/bench-insert-select.js b/benchmarks/bench-insert-select.js index 55540eec63..845d4bedd9 100644 --- a/benchmarks/bench-insert-select.js +++ b/benchmarks/bench-insert-select.js @@ -18,7 +18,7 @@ connection.query( function benchmarkInsert(numLeft, callback) { connection.query( 'INSERT INTO ' + table + ' SET title="' + text + '"', - function(err) { + err => { if (err) throw err; if (numLeft > 1) benchmarkInsert(numLeft - 1, callback); else callback(); @@ -29,7 +29,7 @@ function benchmarkInsert(numLeft, callback) { function benchmarkInserts(n, cb) { const numInsert = 10000; const start = process.hrtime(); - benchmarkInsert(numInsert, function() { + benchmarkInsert(numInsert, () => { const end = process.hrtime(); const diff = common.hrdiff(start, end); console.log((numInsert * 1e9) / diff + ' inserts/sec'); @@ -39,9 +39,7 @@ function benchmarkInserts(n, cb) { } function benchmarkSelect(numLeft, numSelect, callback) { - connection.query('select * from ' + table + ' limit ' + numSelect, function( - err - ) { + connection.query('select * from ' + table + ' limit ' + numSelect, err => { if (err) throw err; if (numLeft > 1) benchmarkSelect(numLeft - 1, numSelect, callback); else callback(); @@ -51,7 +49,7 @@ function benchmarkSelect(numLeft, numSelect, callback) { function benchmarkSelects(n, size, cb) { const numSelects = 100; const start = process.hrtime(); - benchmarkSelect(numSelects, size, function() { + benchmarkSelect(numSelects, size, () => { const end = process.hrtime(); const diff = common.hrdiff(start, end); console.log( @@ -69,10 +67,10 @@ function benchmarkSelects(n, size, cb) { module.exports = function(done) { const testStart = process.hrtime(); - benchmarkInserts(5, function() { - benchmarkSelects(5, 10000, function() { - benchmarkSelects(10, 1000, function() { - benchmarkSelects(2, 50000, function() { + benchmarkInserts(5, () => { + benchmarkSelects(5, 10000, () => { + benchmarkSelects(10, 1000, () => { + benchmarkSelects(2, 50000, () => { const testEnd = process.hrtime(); console.log('total time: ', common.hrdiff(testStart, testEnd) / 1e9); connection.end(); diff --git a/benchmarks/benchmark-query.js b/benchmarks/benchmark-query.js index 5f4452d8bc..157b0c6319 100644 --- a/benchmarks/benchmark-query.js +++ b/benchmarks/benchmark-query.js @@ -11,7 +11,7 @@ const sql = process.argv[2]; const start = Date.now(); let prev1000 = start; function bench() { - db.query(sql).on('end', function() { + db.query(sql).on('end', () => { left--; if (left % 1000 === 0) { const curTime = Date.now(); diff --git a/benchmarks/benchmark-server.js b/benchmarks/benchmark-server.js index 5162889500..7c057411ba 100644 --- a/benchmarks/benchmark-server.js +++ b/benchmarks/benchmark-server.js @@ -8,7 +8,7 @@ function prepareReply(columns, row, n) { const rsHeader = Packets.ResultSetHeader.toPacket(columns.length); length += rsHeader.length(); const columnPackets = []; - columns.forEach(function(column) { + columns.forEach(column => { const packet = Packets.ColumnDefinition.toPacket(column); length += packet.length(); columnPackets.push(packet); @@ -60,7 +60,7 @@ const buff = prepareReply( const server = mysql.createServer(); server.listen('/tmp/mybench3.sock'); -server.on('connection', function(conn) { +server.on('connection', conn => { conn.serverHandshake({ protocolVersion: 10, serverVersion: 'node.js rocks', @@ -69,7 +69,7 @@ server.on('connection', function(conn) { characterSet: 8, capabilityFlags: 0xffffff }); - conn.on('query', function() { + conn.on('query', () => { //console.log(query); conn.write(buff); }); diff --git a/benchmarks/http-select-and-render.js b/benchmarks/http-select-and-render.js index ad07ff4267..b41ab08c37 100644 --- a/benchmarks/http-select-and-render.js +++ b/benchmarks/http-select-and-render.js @@ -9,7 +9,7 @@ const render = common.createTemplate(); const port = process.env.PORT; http - .createServer(function(req, res) { + .createServer((req, res) => { const q = url.parse(req.url, true); if (q.pathname == '/render') { const sql = q.query.q; @@ -24,7 +24,7 @@ http }); res.end(body); } else { - conn.query(sql, function(err, rows) { + conn.query(sql, (err, rows) => { // TODO: handle error rowsTotal = rowsTotal.concat(rows); doQueries(number - 1); diff --git a/benchmarks/ping-pong-client.js b/benchmarks/ping-pong-client.js index 2fe3d49dec..02cc3b4a40 100644 --- a/benchmarks/ping-pong-client.js +++ b/benchmarks/ping-pong-client.js @@ -3,17 +3,17 @@ const net = require('net'); let count = 0; const byte = Buffer.from([0x33]); -function pong() { +function pong(connection) { count++; - this.write(byte); + connection.write(byte); } const c = net.connect(3334); c.setNoDelay(true); -c.ondata = pong; -pong.apply(c); +c.ondata = () => pong(c); +pong(c); -setInterval(function() { +setInterval(() => { console.log(count); count = 0; }, 1000); diff --git a/benchmarks/ping-pong-server.js b/benchmarks/ping-pong-server.js index f945374018..b2cabfcc76 100644 --- a/benchmarks/ping-pong-server.js +++ b/benchmarks/ping-pong-server.js @@ -3,13 +3,13 @@ const net = require('net'); const byte = Buffer.from([0x33]); -function pong() { - this.write(byte); +function pong(conn) { + conn.write(byte); } net - .createServer(function(s) { + .createServer(s => { s.setNoDelay(true); - s.ondata = pong; + s.ondata = () => pong(s); }) .listen(3334); diff --git a/benchmarks/ping-pong-uv.js b/benchmarks/ping-pong-uv.js index 1ff2a4ba2a..6e96eb7ef4 100644 --- a/benchmarks/ping-pong-uv.js +++ b/benchmarks/ping-pong-uv.js @@ -9,9 +9,9 @@ function pong(sock) { writeReq.oncomplete = noop; } -function ping() { +function ping(conn) { count++; - pong(this); + pong(conn); } const port = 3334; @@ -25,10 +25,10 @@ req.oncomplete = function() { console.log('connected'); pong(client); }; -client.onread = ping; +client.onread = () => ping(client); client.readStart(); -setInterval(function() { +setInterval(() => { console.log(count); count = 0; }, 1000); diff --git a/benchmarks/ruby-mysql2/benchmark-query.js b/benchmarks/ruby-mysql2/benchmark-query.js index 33c3b762e7..4ad969ce5e 100644 --- a/benchmarks/ruby-mysql2/benchmark-query.js +++ b/benchmarks/ruby-mysql2/benchmark-query.js @@ -22,7 +22,7 @@ let numRequests = 0; let prev1000 = start; function bench() { //db.query(sql).on('end', function(err, res) { - db.query(sql, function(err, res) { + db.query(sql, (err, res) => { //db.execute(sql, function(err, res) { rowsReceived += res.length; diff --git a/benchmarks/run-unit.js b/benchmarks/run-unit.js index 6e2aa7ee23..78f44a6d45 100755 --- a/benchmarks/run-unit.js +++ b/benchmarks/run-unit.js @@ -12,7 +12,7 @@ const path = require('path'); const prevResults = {}; try { const r = require('./results.json'); - r.forEach(function(rr) { + r.forEach(rr => { prevResults[rr.path] = rr; }); } catch (e) { @@ -37,7 +37,7 @@ function stats(times) { } function runFolder(name, done) { - fs.readdir(name, function(err, list) { + fs.readdir(name, (err, list) => { if (err) return done(err); // eslint-disable-next-line no-use-before-define runFileList(name, list, done); @@ -97,8 +97,8 @@ function benchmarkModule(m, modulePath, done) { return done(null, result); } const start = process.hrtime(); - setImmediate(function() { - m(function() { + setImmediate(() => { + m(() => { const end = process.hrtime(start); if (w <= 0) results.push(end[0] * 1e9 + end[1]); repeat(w - 1, n - 1); @@ -123,7 +123,7 @@ function runFileList(base, list, done) { return done(null, results); } const fname = base + '/' + list[index]; - fs.stat(fname, function(err, stat) { + fs.stat(fname, (err, stat) => { if (err) return done(err); if (stat.isDirectory()) return runFolder(fname, runOne); else if (fname.slice(-3) == '.js') { @@ -137,7 +137,7 @@ function runFileList(base, list, done) { } //const name = process.argv[2] || __dirname + '/unit'; -runFolder(__dirname + '/unit', function(err, results) { +runFolder(__dirname + '/unit', (err, results) => { //console.log(results); fs.writeFileSync(__dirname + '/results.json', JSON.stringify(results)); }); diff --git a/benchmarks/test-benchmark-select-1.js b/benchmarks/test-benchmark-select-1.js index baf4802faf..6f37b3f103 100644 --- a/benchmarks/test-benchmark-select-1.js +++ b/benchmarks/test-benchmark-select-1.js @@ -9,7 +9,7 @@ const createConnection = require('../common').createConnection; const start = Date.now(); let prev1000 = start; function bench() { - db.query('select 1').on('end', function() { + db.query('select 1').on('end', () => { left--; if (left % 1000 === 0) { const curTime = Date.now(); diff --git a/documentation/Authentication-Switch.md b/documentation/Authentication-Switch.md index 8bbcdb6ff1..f903668bc6 100644 --- a/documentation/Authentication-Switch.md +++ b/documentation/Authentication-Switch.md @@ -18,7 +18,7 @@ const conn = mysql.createConnection({ database: 'test_database', authSwitchHandler: function ({pluginName, pluginData}, cb) { if (pluginName === 'ssh-key-auth') { - getPrivateKey(function (key) { + getPrivateKey(key => { const response = encrypt(key, pluginData); // continue handshake by sending response data // respond with error to propagate error to connect/changeUser handlers diff --git a/documentation/Examples.md b/documentation/Examples.md index ff7adaf2fe..dc5a212017 100644 --- a/documentation/Examples.md +++ b/documentation/Examples.md @@ -6,7 +6,7 @@ const mysql = require('mysql2'); const connection = mysql.createConnection({user: 'test', database: 'test'}); -connection.query('SELECT 1+1 as test1', function (err, rows) { +connection.query('SELECT 1+1 as test1', (err, rows) => { // }); ``` @@ -17,7 +17,7 @@ connection.query('SELECT 1+1 as test1', function (err, rows) { const mysql = require('mysql2'); const connection = mysql.createConnection({user: 'test', database: 'test'}); -connection.execute('SELECT 1+? as test1', [10], function (err, rows) { +connection.execute('SELECT 1+? as test1', [10], (err, rows) => { // }); ``` @@ -49,7 +49,7 @@ const connection = mysql.createConnection({ ssl: 'Amazon RDS' }); -conn.query('show status like \'Ssl_cipher\'', function (err, res) { +conn.query('show status like \'Ssl_cipher\'', (err, res) => { console.log(err, res); conn.end(); }); @@ -63,7 +63,7 @@ const mysql = require('mysql2'); const server = mysql.createServer(); server.listen(3307); -server.on('connection', function (conn) { +server.on('connection', conn => { console.log('connection'); conn.serverHandshake({ @@ -75,14 +75,14 @@ server.on('connection', function (conn) { capabilityFlags: 0xffffff }); - conn.on('field_list', function (table, fields) { + conn.on('field_list', (table, fields) => { console.log('field list:', table, fields); conn.writeEof(); }); const remote = mysql.createConnection({user: 'root', database: 'dbname', host:'server.example.com', password: 'secret'}); - conn.on('query', function (sql) { + conn.on('query', sql => { console.log('proxying query:' + sql); remote.query(sql, function (err) { // overloaded args, either (err, result :object) diff --git a/documentation/Extras.md b/documentation/Extras.md index b56ecf117b..2e1beca012 100644 --- a/documentation/Extras.md +++ b/documentation/Extras.md @@ -6,16 +6,16 @@ You can use named placeholders for parameters by setting `namedPlaceholders` con ```js connection.config.namedPlaceholders = true; - connection.execute('select :x + :y as z', {x: 1, y: 2}, function (err, rows) { + connection.execute('select :x + :y as z', {x: 1, y: 2}, (err, rows) => { // statement prepared as "select ? + ? as z" and executed with [1,2] values // rows returned: [ { z: 3 } ] }); - connection.execute('select :x + :x as z', {x: 1}, function (err, rows) { + connection.execute('select :x + :x as z', {x: 1}, (err, rows) => { // select ? + ? as z, execute with [1, 1] }); - connection.query('select :x + :x as z', {x: 1}, function (err, rows) { + connection.query('select :x + :x as z', {x: 1}, (err, rows) => { // query select 1 + 1 as z }); ``` @@ -24,7 +24,7 @@ You can use named placeholders for parameters by setting `namedPlaceholders` con ```js const options = {sql: 'select A,B,C,D from foo', rowsAsArray: true}; -connection.query(options, function (err, results) { +connection.query(options, (err, results) => { /* results will be an array of arrays like this now: [[ 'field A value', diff --git a/documentation/Prepared-Statements.md b/documentation/Prepared-Statements.md index 2d17370fe9..5e1b4d05bb 100644 --- a/documentation/Prepared-Statements.md +++ b/documentation/Prepared-Statements.md @@ -5,7 +5,7 @@ Similar to `connection.query()`. ```js -connection.execute('select 1 + ? + ? as result', [5, 6], function (err, rows) { +connection.execute('select 1 + ? + ? as result', [5, 6], (err, rows) => { // rows: [ { result: 12 } ] // internally 'select 1 + ? + ? as result' is prepared first. On subsequent calls cached statement is re-used }); @@ -17,13 +17,13 @@ connection.unprepare('select 1 + ? + ? as result'); ## Manual prepare / execute ```js -connection.prepare('select ? + ? as tests', function (err, statement) { +connection.prepare('select ? + ? as tests', (err, statement) => { // statement.parameters - array of column definitions, length === number of params, here 2 // statement.columns - array of result column definitions. Can be empty if result schema is dynamic / not known // statement.id // statement.query - statement.execute([1, 2], function (err, rows, columns) { + statement.execute([1, 2], (err, rows, columns) => { // -> [ { tests: 3 } ] }); diff --git a/documentation/Promise-Wrapper.md b/documentation/Promise-Wrapper.md index be91dccd06..a8105de805 100644 --- a/documentation/Promise-Wrapper.md +++ b/documentation/Promise-Wrapper.md @@ -8,20 +8,20 @@ In addition to errback interface there is thin wrapper to expose Promise-based a /* eslint-env es6 */ const mysql = require('mysql2/promise'); // or require('mysql2').createConnectionPromise mysql.createConnection({ /* same parameters as for non-promise createConnection */ }) - .then((conn) => conn.query('select foo from bar')) + .then(conn => conn.query('select foo from bar')) .then(([rows, fields]) => console.log(rows[0].foo)); ``` ```js const pool = require('mysql2/promise').createPool({}); // or mysql.createPoolPromise({}) pool.getConnection() - .then((conn) => { + .then(conn => { const res = conn.query('select foo from bar'); conn.release(); return res; - }).then((result) => { + }).then(result => { console.log(result[0][0].foo); - }).catch((err) => { + }).catch(err => { console.log(err); // any of connection time or query time errors from above }); ``` diff --git a/examples/binlog-watcher.js b/examples/binlog-watcher.js index a67d132bd2..04f4105420 100644 --- a/examples/binlog-watcher.js +++ b/examples/binlog-watcher.js @@ -13,7 +13,7 @@ const binlogStream = mysql.createBinlogStream({ }); binlogStream.pipe( - through2.obj(function(obj, enc, next) { + through2.obj((obj, enc, next) => { console.log(obj); next(); }) diff --git a/examples/connect-over-socks.js b/examples/connect-over-socks.js index b52d79828a..8175b6a03f 100644 --- a/examples/connect-over-socks.js +++ b/examples/connect-over-socks.js @@ -19,14 +19,14 @@ const conn1 = mysql.createPool({ } }); -conn1.execute('select sleep(1.1) as www', function(err, rows, fields) { +conn1.execute('select sleep(1.1) as www', (err, rows, fields) => { console.log(err, rows, fields); }); -conn1.execute('select sleep(1) as qqq', function(err, rows, fields) { +conn1.execute('select sleep(1) as qqq', (err, rows, fields) => { console.log(err, rows, fields); }); -conn1.execute('select sleep(1) as qqq', function(err, rows, fields) { +conn1.execute('select sleep(1) as qqq', (err, rows, fields) => { console.log(err, rows, fields); }); diff --git a/examples/execute.js b/examples/execute.js index 2570e99f3d..e40a6bfa9f 100644 --- a/examples/execute.js +++ b/examples/execute.js @@ -13,18 +13,18 @@ const connection = mysql.createConnection({ connection.execute( 'select ?+1 as qqq, ? as rrr, ? as yyy', [1, null, 3], - function(err, rows, fields) { + (err, rows, fields) => { console.log(err, rows, fields); connection.execute( 'select ?+1 as qqq, ? as rrr, ? as yyy', [3, null, 3], - function(err, rows, fields) { + (err, rows, fields) => { console.log(err, rows, fields); connection.unprepare('select ?+1 as qqq, ? as rrr, ? as yyy'); connection.execute( 'select ?+1 as qqq, ? as rrr, ? as yyy', [3, null, 3], - function(err, rows, fields) { + (err, rows, fields) => { console.log(err, rows, fields); } ); diff --git a/examples/mysqlproxy.js b/examples/mysqlproxy.js index 0e93f9c104..1f79bf291f 100644 --- a/examples/mysqlproxy.js +++ b/examples/mysqlproxy.js @@ -6,7 +6,7 @@ const ClientFlags = require('mysql2/lib/constants/client.js'); const server = mysql.createServer(); server.listen(3307); -server.on('connection', function(conn) { +server.on('connection', conn => { console.log('connection'); conn.serverHandshake({ @@ -18,7 +18,7 @@ server.on('connection', function(conn) { capabilityFlags: 0xffffff ^ ClientFlags.COMPRESS }); - conn.on('field_list', function(table, fields) { + conn.on('field_list', (table, fields) => { console.log('field list:', table, fields); conn.writeEof(); }); @@ -30,7 +30,7 @@ server.on('connection', function(conn) { password: 'secret' }); - conn.on('query', function(sql) { + conn.on('query', sql => { console.log('proxying query:' + sql); remote.query(sql, function(err) { // overloaded args, either (err, result :object) diff --git a/examples/pass-sha.js b/examples/pass-sha.js index 888e5971af..ae96362cb1 100644 --- a/examples/pass-sha.js +++ b/examples/pass-sha.js @@ -7,10 +7,10 @@ const mysql = require('mysql2').createConnection({ passwordSha1: Buffer.from('8bb6118f8fd6935ad0876a3be34a717d32708ffd', 'hex') }); -mysql.execute('select ?+1 as qqq, ? as rrr, ? as yyy', [1, null, 3], function( - err, - rows, - fields -) { - console.log(err, rows, fields); -}); +mysql.execute( + 'select ?+1 as qqq, ? as rrr, ? as yyy', + [1, null, 3], + (err, rows, fields) => { + console.log(err, rows, fields); + } +); diff --git a/examples/pool-test.js b/examples/pool-test.js index d6182019df..922e1c45ec 100644 --- a/examples/pool-test.js +++ b/examples/pool-test.js @@ -7,19 +7,19 @@ const pool = require('mysql2').createPool({ password: 'root' }); -setInterval(function() { +setInterval(() => { for (let i = 0; i < 5; ++i) { - pool.query(function(err, db) { + pool.query((err, db) => { console.log(rows, fields); // Connection is automatically released once query resolves }); } }, 1000); -setInterval(function() { +setInterval(() => { for (let i = 0; i < 5; ++i) { - pool.getConnection(function(err, db) { - db.query('select sleep(0.5) as qqq', function(err, rows, fields) { + pool.getConnection((err, db) => { + db.query('select sleep(0.5) as qqq', (err, rows, fields) => { console.log(rows, fields); db.release(); }); diff --git a/examples/prepare.js b/examples/prepare.js index f2580a9227..fb36f070c7 100644 --- a/examples/prepare.js +++ b/examples/prepare.js @@ -14,7 +14,7 @@ const connection = mysql.createConnection({ connection.execute( 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Rick C-137', 53], - function(err, results, fields) { + (err, results, fields) => { console.log(results); // results contains rows returned by server console.log(fields); // fields contains extra meta data about results, if available diff --git a/examples/server.js b/examples/server.js index 62407e6c41..bea9c05a7b 100644 --- a/examples/server.js +++ b/examples/server.js @@ -23,7 +23,7 @@ function authenticate(params, cb) { const server = mysql.createServer(); server.listen(3333); -server.on('connection', function(conn) { +server.on('connection', conn => { // we can deny connection here: // conn.writeError({ message: 'secret', code: 123 }); // conn.close(); @@ -39,12 +39,12 @@ server.on('connection', function(conn) { authCallback: authenticate }); - conn.on('field_list', function(table, fields) { + conn.on('field_list', (table, fields) => { console.log('FIELD LIST:', table, fields); conn.writeEof(); }); - conn.on('query', function(query) { + conn.on('query', query => { conn.writeColumns([ { catalog: 'def', diff --git a/examples/simple-select.js b/examples/simple-select.js index b640a0d93c..c38352b44b 100644 --- a/examples/simple-select.js +++ b/examples/simple-select.js @@ -13,7 +13,7 @@ const connection = mysql.createConnection({ // simple query connection.query( 'SELECT * FROM `table` WHERE `name` = "Page" AND `age` > 45', - function(err, results, fields) { + (err, results, fields) => { console.log(results); // results contains rows returned by server console.log(fields); // fields contains extra meta data about results, if available } @@ -23,7 +23,7 @@ connection.query( connection.query( 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Page', 45], - function(err, results) { + (err, results) => { console.log(results); } ); diff --git a/index.js b/index.js index 067ffda227..f186ae6502 100644 --- a/index.js +++ b/index.js @@ -44,29 +44,30 @@ exports.escapeId = SqlString.escapeId; exports.format = SqlString.format; exports.raw = SqlString.raw; -exports.__defineGetter__('createConnectionPromise', function() { - return require('./promise.js').createConnection; -}); - -exports.__defineGetter__('createPoolPromise', function() { - return require('./promise.js').createPool; -}); - -exports.__defineGetter__('createPoolClusterPromise', function() { - return require('./promise.js').createPoolCluster; -}); - -exports.__defineGetter__('Types', function() { - return require('./lib/constants/types.js'); -}); - -exports.__defineGetter__('Charsets', function() { - return require('./lib/constants/charsets.js'); -}); - -exports.__defineGetter__('CharsetToEncoding', function() { - return require('./lib/constants/charset_encodings.js'); -}); +exports.__defineGetter__( + 'createConnectionPromise', + () => require('./promise.js').createConnection +); + +exports.__defineGetter__( + 'createPoolPromise', + () => require('./promise.js').createPool +); + +exports.__defineGetter__( + 'createPoolClusterPromise', + () => require('./promise.js').createPoolCluster +); + +exports.__defineGetter__('Types', () => require('./lib/constants/types.js')); + +exports.__defineGetter__('Charsets', () => + require('./lib/constants/charsets.js') +); + +exports.__defineGetter__('CharsetToEncoding', () => + require('./lib/constants/charset_encodings.js') +); exports.setMaxParserCache = function(max) { parserCache.setMaxCache(max); diff --git a/lib/commands/client_handshake.js b/lib/commands/client_handshake.js index 2da31e6a7a..a1234bf93f 100644 --- a/lib/commands/client_handshake.js +++ b/lib/commands/client_handshake.js @@ -85,8 +85,7 @@ class ClientHandshake extends Command { } handshakeInit(helloPacket, connection) { - const command = this; - this.on('error', function(e) { + this.on('error', e => { connection._fatalError = e; connection._protocolError = e; }); @@ -115,23 +114,23 @@ class ClientHandshake extends Command { const err = new Error('Server does not support secure connnection'); err.code = 'HANDSHAKE_NO_SSL_SUPPORT'; err.fatal = true; - command.emit('error', err); + this.emit('error', err); return false; } // send ssl upgrade request and immediately upgrade connection to secure this.clientFlags |= ClientConstants.SSL; this.sendSSLRequest(connection); - connection.startTLS(function(err) { + connection.startTLS(err => { // after connection is secure if (err) { // SSL negotiation error are fatal err.code = 'HANDSHAKE_SSL_ERROR'; err.fatal = true; - command.emit('error', err); + this.emit('error', err); return; } // rest of communication is encrypted - command.sendCredentials(connection); + this.sendCredentials(connection); }); } else { this.sendCredentials(connection); @@ -160,18 +159,18 @@ class ClientHandshake extends Command { new Packets.AuthSwitchResponse(authToken).toPacket() ); } else if (connection.config.authSwitchHandler) { - connection.config.authSwitchHandler(authSwitchHandlerParams, function( - err, - data - ) { - if (err) { - connection.emit('error', err); - return; + connection.config.authSwitchHandler( + authSwitchHandlerParams, + (err, data) => { + if (err) { + connection.emit('error', err); + return; + } + connection.writePacket( + new Packets.AuthSwitchResponse(data).toPacket() + ); } - connection.writePacket( - new Packets.AuthSwitchResponse(data).toPacket() - ); - }); + ); } else { connection.emit( 'error', diff --git a/lib/commands/index.js b/lib/commands/index.js index 4c2ddab4ec..96dcd16d8a 100644 --- a/lib/commands/index.js +++ b/lib/commands/index.js @@ -2,7 +2,7 @@ 'client_handshake server_handshake query prepare close_statement execute ping register_slave binlog_dump change_user quit' .split(' ') - .forEach(function(name) { + .forEach(name => { const ctor = require('./' + name + '.js'); module.exports[ctor.name] = ctor; }); diff --git a/lib/commands/prepare.js b/lib/commands/prepare.js index d7421b326a..0a2238616c 100644 --- a/lib/commands/prepare.js +++ b/lib/commands/prepare.js @@ -112,17 +112,16 @@ class Prepare extends Command { } prepareDone(connection) { - const self = this; const statement = new PreparedStatementInfo( - self.query, - self.id, - self.fields, - self.parameterDefinitions, + this.query, + this.id, + this.fields, + this.parameterDefinitions, connection ); connection._statements.set(this.key, statement); if (this.onResult) { - self.onResult(null, statement); + this.onResult(null, statement); } return null; } diff --git a/lib/commands/query.js b/lib/commands/query.js index 3d488093f0..21e497f4d8 100644 --- a/lib/commands/query.js +++ b/lib/commands/query.js @@ -57,7 +57,6 @@ class Query extends Command { } done() { - const self = this; this._unpipeStream(); if (this.onResult) { let rows, fields; @@ -69,12 +68,12 @@ class Query extends Command { fields = this._fields; } if (fields) { - process.nextTick(function() { - self.onResult(null, rows, fields); + process.nextTick(() => { + this.onResult(null, rows, fields); }); } else { - process.nextTick(function() { - self.onResult(null, rows); + process.nextTick(() => { + this.onResult(null, rows); }); } } @@ -141,12 +140,11 @@ class Query extends Command { } _streamLocalInfile(connection) { - const command = this; - const onDrain = function() { - command._localStream.resume(); + const onDrain = () => { + this._localStream.resume(); }; - const onPause = function() { - command._localStream.pause(); + const onPause = () => { + this._localStream.pause(); }; const onData = function(data) { const dataWithHeader = Buffer.allocUnsafe(data.length + 4); @@ -155,27 +153,27 @@ class Query extends Command { new Packets.Packet(0, dataWithHeader, 0, dataWithHeader.length) ); }; - const onEnd = function() { + const onEnd = () => { connection.writePacket(EmptyPacket); }; - const onError = function(err) { - command._localStreamError = err; + const onError = err => { + this._localStreamError = err; connection.writePacket(EmptyPacket); }; - command._unpipeStream = function() { + this._unpipeStream = () => { connection.stream.removeListener('pause', onPause); connection.stream.removeListener('drain', onDrain); - command._localStream.removeListener('data', onData); - command._localStream.removeListener('end', onEnd); - command._localStream.removeListener('error', onError); + this._localStream.removeListener('data', onData); + this._localStream.removeListener('end', onEnd); + this._localStream.removeListener('error', onError); }; connection.stream.on('pause', onPause); connection.stream.on('drain', onDrain); - command._localStream.on('data', onData); - command._localStream.on('end', onEnd); - command._localStream.on('error', onError); + this._localStream.on('data', onData); + this._localStream.on('end', onEnd); + this._localStream.on('error', onError); connection.once('error', () => { - command._unpipeStream(); + this._unpipeStream(); }); } @@ -260,14 +258,14 @@ class Query extends Command { } stream.emit('result', row); // replicate old emitter }); - this.on('error', function(err) { + this.on('error', err => { stream.emit('error', err); // Pass on any errors }); - this.on('end', function() { + this.on('end', () => { stream.push(null); // pushing null, indicating EOF stream.emit('close'); // notify readers that query has completed }); - this.on('fields', function(fields) { + this.on('fields', fields => { stream.emit('fields', fields); // replicate old emitter }); return stream; diff --git a/lib/commands/server_handshake.js b/lib/commands/server_handshake.js index f0e1d894fa..3ca4049bd0 100644 --- a/lib/commands/server_handshake.js +++ b/lib/commands/server_handshake.js @@ -23,7 +23,7 @@ class ServerHandshake extends Command { start(packet, connection) { const serverHelloPacket = new Packets.Handshake(this.args); this.serverHello = serverHelloPacket; - serverHelloPacket.setScrambleData(function(err) { + serverHelloPacket.setScrambleData(err => { if (err) { connection.emit('error', new Error('Error generating random bytes')); return; @@ -49,7 +49,7 @@ class ServerHandshake extends Command { authPluginData2: this.serverHello.authPluginData2, authToken: clientHelloReply.authToken }, - function(err, mysqlError) { + (err, mysqlError) => { // if (err) if (!mysqlError) { connection.writeOk(); diff --git a/lib/compressed_protocol.js b/lib/compressed_protocol.js index fc1c354ae7..67a7c39c32 100644 --- a/lib/compressed_protocol.js +++ b/lib/compressed_protocol.js @@ -7,13 +7,14 @@ const zlib = require('zlib'); const PacketParser = require('./packet_parser.js'); function handleCompressedPacket(packet) { + // eslint-disable-next-line consistent-this, no-invalid-this const connection = this; const deflatedLength = packet.readInt24(); const body = packet.readBuffer(); if (deflatedLength !== 0) { - connection.inflateQueue.push(function(task) { - zlib.inflate(body, function(err, data) { + connection.inflateQueue.push(task => { + zlib.inflate(body, (err, data) => { if (err) { connection._handleNetworkError(err); return; @@ -24,7 +25,7 @@ function handleCompressedPacket(packet) { }); }); } else { - connection.inflateQueue.push(function(task) { + connection.inflateQueue.push(task => { connection._bumpCompressedSequenceId(packet.numPackets); connection._inflatedPacketsParser.execute(body); task.done(); @@ -44,6 +45,7 @@ function writeCompressed(buffer) { if (buffer.length > MAX_COMPRESSED_LENGTH) { for (start = 0; start < buffer.length; start += MAX_COMPRESSED_LENGTH) { writeCompressed.call( + // eslint-disable-next-line no-invalid-this this, buffer.slice(start, start + MAX_COMPRESSED_LENGTH) ); @@ -51,6 +53,7 @@ function writeCompressed(buffer) { return; } + // eslint-disable-next-line no-invalid-this, consistent-this const connection = this; let packetLen = buffer.length; @@ -60,8 +63,8 @@ function writeCompressed(buffer) { // internally and when we have multiple compressed packets arriving we need // to assemble uncompressed result sequentially (function(seqId) { - connection.deflateQueue.push(function(task) { - zlib.deflate(buffer, function(err, compressed) { + connection.deflateQueue.push(task => { + zlib.deflate(buffer, (err, compressed) => { if (err) { connection._handleFatalError(err); return; @@ -103,11 +106,11 @@ function enableCompression(connection) { connection._lastReceivedPacketId = 0; connection._handleCompressedPacket = handleCompressedPacket; - connection._inflatedPacketsParser = new PacketParser(function(p) { + connection._inflatedPacketsParser = new PacketParser(p => { connection.handlePacket(p); }, 4); connection._inflatedPacketsParser._lastPacket = 0; - connection.packetParser = new PacketParser(function(packet) { + connection.packetParser = new PacketParser(packet => { connection._handleCompressedPacket(packet); }, 7); diff --git a/lib/connection.js b/lib/connection.js index cc7e6aa0a8..910dd00c99 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -58,7 +58,6 @@ class Connection extends EventEmitter { }); this.serverCapabilityFlags = 0; this.authorized = false; - const connection = this; this.sequenceId = 0; this.compressedSequenceId = 0; this.threadId = null; @@ -67,49 +66,49 @@ class Connection extends EventEmitter { this._protocolError = null; this._outOfOrderPackets = []; this.clientEncoding = CharsetToEncoding[this.config.charsetNumber]; - this.stream.on('error', connection._handleNetworkError.bind(this)); + this.stream.on('error', this._handleNetworkError.bind(this)); // see https://gist.github.com/khoomeister/4985691#use-that-instead-of-bind - this.packetParser = new PacketParser(function(p) { - connection.handlePacket(p); + this.packetParser = new PacketParser(p => { + this.handlePacket(p); }); - this.stream.on('data', function(data) { - if (connection.connectTimeout) { - Timers.clearTimeout(connection.connectTimeout); - connection.connectTimeout = null; + this.stream.on('data', data => { + if (this.connectTimeout) { + Timers.clearTimeout(this.connectTimeout); + this.connectTimeout = null; } - connection.packetParser.execute(data); + this.packetParser.execute(data); }); - this.stream.on('close', function() { + this.stream.on('close', () => { // we need to set this flag everywhere where we want connection to close - if (connection._closing) { + if (this._closing) { return; } - if (!connection._protocolError) { + if (!this._protocolError) { // no particular error message before disconnect - connection._protocolError = new Error( + this._protocolError = new Error( 'Connection lost: The server closed the connection.' ); - connection._protocolError.fatal = true; - connection._protocolError.code = 'PROTOCOL_CONNECTION_LOST'; + this._protocolError.fatal = true; + this._protocolError.code = 'PROTOCOL_CONNECTION_LOST'; } - connection._notifyError(connection._protocolError); + this._notifyError(this._protocolError); }); let handshakeCommand; if (!this.config.isServer) { handshakeCommand = new Commands.ClientHandshake(this.config.clientFlags); - handshakeCommand.on('end', function() { + handshakeCommand.on('end', () => { // this happens when handshake finishes early and first packet is error // and not server hello ( for example, 'Too many connactions' error) if (!handshakeCommand.handshake) { return; } - connection._handshakePacket = handshakeCommand.handshake; - connection.threadId = handshakeCommand.handshake.connectionId; - connection.emit('connect', handshakeCommand.handshake); + this._handshakePacket = handshakeCommand.handshake; + this.threadId = handshakeCommand.handshake.connectionId; + this.emit('connect', handshakeCommand.handshake); }); - handshakeCommand.on('error', function(err) { - connection._closing = true; - connection._notifyError(err); + handshakeCommand.on('error', err => { + this._closing = true; + this._notifyError(err); }); this.addCommand(handshakeCommand); } @@ -144,16 +143,15 @@ class Connection extends EventEmitter { } _handleFatalError(err) { - const connection = this; err.fatal = true; // stop receiving packets - connection.stream.removeAllListeners('data'); - connection.addCommand = connection._addCommandClosedState; - connection.write = function() { - connection.emit('error', new Error("Can't write in closed state")); + this.stream.removeAllListeners('data'); + this.addCommand = this._addCommandClosedState; + this.write = () => { + this.emit('error', new Error("Can't write in closed state")); }; - connection._notifyError(err); - connection._fatalError = err; + this._notifyError(err); + this._fatalError = err; } _handleNetworkError(err) { @@ -180,33 +178,32 @@ class Connection extends EventEmitter { // notify all commands in the queue and bubble error as connection "error" // called on stream error or unexpected termination _notifyError(err) { - const connection = this; // prevent from emitting 'PROTOCOL_CONNECTION_LOST' after EPIPE or ECONNRESET - if (connection._fatalError) { + if (this._fatalError) { return; } let command; // if there is no active command, notify connection // if there are commands and all of them have callbacks, pass error via callback - let bubbleErrorToConnection = !connection._command; - if (connection._command && connection._command.onResult) { - connection._command.onResult(err); - connection._command = null; + let bubbleErrorToConnection = !this._command; + if (this._command && this._command.onResult) { + this._command.onResult(err); + 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 ( !( - connection._command && - connection._command.constructor == Commands.ClientHandshake && - connection._commands.length > 0 + this._command && + this._command.constructor == Commands.ClientHandshake && + this._commands.length > 0 ) ) { bubbleErrorToConnection = true; } } - while ((command = connection._commands.shift())) { + while ((command = this._commands.shift())) { if (command.onResult) { command.onResult(err); } else { @@ -215,16 +212,15 @@ class Connection extends EventEmitter { } // notify connection if some comands in the queue did not have callbacks // or if this is pool connection ( so it can be removed from pool ) - if (bubbleErrorToConnection || connection._pool) { - connection.emit('error', err); + if (bubbleErrorToConnection || this._pool) { + this.emit('error', err); } } write(buffer) { - const connection = this; - this.stream.write(buffer, function(err) { + this.stream.write(buffer, err => { if (err) { - connection._handleNetworkError(err); + this._handleNetworkError(err); } }); } @@ -329,7 +325,6 @@ class Connection extends EventEmitter { // eslint-disable-next-line no-console console.log('Upgrading connection to TLS'); } - const connection = this; const secureContext = Tls.createSecureContext({ ca: this.config.ssl.ca, cert: this.config.ssl.cert, @@ -339,28 +334,28 @@ class Connection extends EventEmitter { }); const rejectUnauthorized = this.config.ssl.rejectUnauthorized; let secureEstablished = false; - const secureSocket = new Tls.TLSSocket(connection.stream, { + const secureSocket = new Tls.TLSSocket(this.stream, { rejectUnauthorized: rejectUnauthorized, requestCert: true, secureContext: secureContext, isServer: false }); // error handler for secure socket - secureSocket.on('_tlsError', function(err) { + secureSocket.on('_tlsError', err => { if (secureEstablished) { - connection._handleNetworkError(err); + this._handleNetworkError(err); } else { onSecure(err); } }); - secureSocket.on('secure', function() { + secureSocket.on('secure', () => { secureEstablished = true; - onSecure(rejectUnauthorized ? this.ssl.verifyError() : null); + onSecure(rejectUnauthorized ? secureSocket.ssl.verifyError() : null); }); - secureSocket.on('data', function(data) { - connection.packetParser.execute(data); + secureSocket.on('data', data => { + this.packetParser.execute(data); }); - connection.write = function(buffer) { + this.write = buffer => { secureSocket.write(buffer); }; // start TLS communications @@ -368,14 +363,13 @@ class Connection extends EventEmitter { } pipe() { - const connection = this; if (this.stream instanceof Net.Stream) { - this.stream.ondata = function(data, start, end) { - connection.packetParser.execute(data, start, end); + this.stream.ondata = (data, start, end) => { + this.packetParser.execute(data, start, end); }; } else { - this.stream.on('data', function(data) { - connection.packetParser.execute( + this.stream.on('data', data => { + this.packetParser.execute( data.parent, data.offset, data.offset + data.length @@ -606,14 +600,14 @@ class Connection extends EventEmitter { // check for values containing undefined if (options.values) { //If namedPlaceholder is not enabled and object is passed as bind parameters - if (!(options.values instanceof Array)) { + if (!Array.isArray(options.values)) { throw new TypeError( 'Bind parameters must be array if namedPlaceholders parameter is not enabled' ); } - options.values.forEach(function(val) { + options.values.forEach(val => { //If namedPlaceholder is not enabled and object is passed as bind parameters - if (!(options.values instanceof Array)) { + if (!Array.isArray(options.values)) { throw new TypeError( 'Bind parameters must be array if namedPlaceholders parameter is not enabled' ); @@ -631,7 +625,7 @@ class Connection extends EventEmitter { }); } const executeCommand = new Commands.Execute(options, cb); - const prepareCommand = new Commands.Prepare(options, function(err, stmt) { + const prepareCommand = new Commands.Prepare(options, (err, stmt) => { if (err) { // skip execute command if prepare failed, we have main // combined callback here @@ -672,7 +666,7 @@ class Connection extends EventEmitter { charsetNumber: charsetNumber, currentConfig: this.config }, - function(err) { + err => { if (err) { err.fatal = true; } @@ -721,8 +715,7 @@ class Connection extends EventEmitter { } this._closing = true; this.stream.end(); - const connection = this; - connection.addCommand = connection._addCommandClosedState; + this.addCommand = this._addCommandClosedState; } createBinlogStream(opts) { @@ -777,14 +770,10 @@ class Connection extends EventEmitter { // outgoing server connection methods // =================================== writeColumns(columns) { - const connection = this; this.writePacket(Packets.ResultSetHeader.toPacket(columns.length)); - columns.forEach(function(column) { - connection.writePacket( - Packets.ColumnDefinition.toPacket( - column, - connection.serverConfig.encoding - ) + columns.forEach(column => { + this.writePacket( + Packets.ColumnDefinition.toPacket(column, this.serverConfig.encoding) ); }); this.writeEof(); @@ -798,16 +787,15 @@ class Connection extends EventEmitter { } writeTextResult(rows, columns) { - const connection = this; - connection.writeColumns(columns); - rows.forEach(function(row) { + this.writeColumns(columns); + rows.forEach(row => { const arrayRow = new Array(columns.length); - columns.forEach(function(column) { + columns.forEach(column => { arrayRow.push(row[column.name]); }); - connection.writeTextRow(arrayRow); + this.writeTextRow(arrayRow); }); - connection.writeEof(); + this.writeEof(); } writeEof(warnings, statusFlags) { @@ -896,7 +884,6 @@ if (Tls.TLSSocket) { // eslint-disable-next-line no-console console.log('Upgrading connection to TLS'); } - const connection = this; const crypto = require('crypto'); const config = this.config; const stream = this.stream; @@ -921,14 +908,14 @@ if (Tls.TLSSocket) { stream.removeAllListeners('data'); stream.pipe(securePair.encrypted); securePair.encrypted.pipe(stream); - securePair.cleartext.on('data', function(data) { - connection.packetParser.execute(data); + securePair.cleartext.on('data', data => { + this.packetParser.execute(data); }); - connection.write = function(buffer) { + this.write = function(buffer) { securePair.cleartext.write(buffer); }; - securePair.on('secure', function() { - onSecure(rejectUnauthorized ? this.ssl.verifyError() : null); + securePair.on('secure', () => { + onSecure(rejectUnauthorized ? securePair.ssl.verifyError() : null); }); }; } diff --git a/lib/packets/change_user.js b/lib/packets/change_user.js index d547be8150..e0449e4951 100644 --- a/lib/packets/change_user.js +++ b/lib/packets/change_user.js @@ -38,10 +38,7 @@ class ChangeUser { // ChangeUser.fromPacket = function(packet) // }; serializeToBuffer(buffer) { - const self = this; - function isSet(flag) { - return self.flags & ClientConstants[flag]; - } + const isSet = flag => this.flags & ClientConstants[flag]; const packet = new Packet(0, buffer, 0, buffer.length); packet.offset = 4; const encoding = CharsetToEncoding[this.charsetNumber]; diff --git a/lib/packets/column_definition.js b/lib/packets/column_definition.js index c3bf0bb1af..c00ddf956e 100644 --- a/lib/packets/column_definition.js +++ b/lib/packets/column_definition.js @@ -72,7 +72,7 @@ class ColumnDefinition { static toPacket(column, sequenceId) { let length = 17; // = 4 padding + 1 + 12 for the rest - fields.forEach(function(field) { + fields.forEach(field => { length += Packet.lengthCodedStringLength( column[field], CharsetToEncoding[column.characterSet] diff --git a/lib/packets/execute.js b/lib/packets/execute.js index 663a95812d..9e36af0d92 100644 --- a/lib/packets/execute.js +++ b/lib/packets/execute.js @@ -22,6 +22,7 @@ function toParameter(value, encoding) { let type = Types.VAR_STRING; let length; let writer = function(value) { + // eslint-disable-next-line no-invalid-this return Packet.prototype.writeLengthCodedString.call(this, value, encoding); }; if (value !== null) { @@ -77,7 +78,6 @@ class Execute { } toPacket() { - const self = this; // TODO: don't try to calculate packet length in advance, allocate some big buffer in advance (header + 256 bytes?) // and copy + reallocate if not enough // 0 + 4 - length, seqId @@ -91,12 +91,13 @@ class Execute { length += Math.floor((this.parameters.length + 7) / 8); length += 1; // new-params-bound-flag length += 2 * this.parameters.length; // type byte for each parameter if new-params-bound-flag is set - parameters = this.parameters.map(function(value) { - return toParameter(value, self.encoding); - }); - length += parameters.reduce(function(accumulator, parameter) { - return accumulator + parameter.length; - }, 0); + parameters = this.parameters.map(value => + toParameter(value, this.encoding) + ); + length += parameters.reduce( + (accumulator, parameter) => accumulator + parameter.length, + 0 + ); } const buffer = Buffer.allocUnsafe(length); const packet = new Packet(0, buffer, 0, length); @@ -108,7 +109,7 @@ class Execute { if (parameters) { let bitmap = 0; let bitValue = 1; - parameters.forEach(function(parameter) { + parameters.forEach(parameter => { if (parameter.type === Types.NULL) { bitmap += bitValue; } @@ -127,12 +128,12 @@ class Execute { // if not, previous execution types are used (TODO prooflink) packet.writeInt8(1); // new-params-bound-flag // Write parameter types - parameters.forEach(function(parameter) { + parameters.forEach(parameter => { packet.writeInt8(parameter.type); // field type packet.writeInt8(0); // parameter flag }); // Write parameter values - parameters.forEach(function(parameter) { + parameters.forEach(parameter => { if (parameter.type !== Types.NULL) { parameter.writer.call(packet, parameter.value); } diff --git a/lib/packets/handshake.js b/lib/packets/handshake.js index 916fafab69..777f73fc6f 100644 --- a/lib/packets/handshake.js +++ b/lib/packets/handshake.js @@ -15,14 +15,13 @@ class Handshake { } setScrambleData(cb) { - const self = this; - require('crypto').randomBytes(20, function(err, data) { + require('crypto').randomBytes(20, (err, data) => { if (err) { cb(err); return; } - self.authPluginData1 = data.slice(0, 8); - self.authPluginData2 = data.slice(8, 20); + this.authPluginData1 = data.slice(0, 8); + this.authPluginData2 = data.slice(8, 20); cb(); }); } diff --git a/lib/packets/handshake_response.js b/lib/packets/handshake_response.js index 420c5d6bdd..c05543e657 100644 --- a/lib/packets/handshake_response.js +++ b/lib/packets/handshake_response.js @@ -38,10 +38,7 @@ class HandshakeResponse { } serializeResponse(buffer) { - const self = this; - function isSet(flag) { - return self.clientFlags & ClientConstants[flag]; - } + const isSet = flag => this.clientFlags & ClientConstants[flag]; const packet = new Packet(0, buffer, 0, buffer.length); packet.offset = 4; packet.writeInt32(this.clientFlags); diff --git a/lib/packets/index.js b/lib/packets/index.js index 69874a90b0..670d9249b3 100644 --- a/lib/packets/index.js +++ b/lib/packets/index.js @@ -2,7 +2,7 @@ '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(function(name) { + .forEach(name => { const ctor = require('./' + name + '.js'); module.exports[ctor.name] = ctor; // monkey-patch it to include name if debug is on diff --git a/lib/packets/text_row.js b/lib/packets/text_row.js index f9f9844671..b04be4c9b0 100644 --- a/lib/packets/text_row.js +++ b/lib/packets/text_row.js @@ -19,7 +19,7 @@ class TextRow { static toPacket(columns, encoding) { const sequenceId = 0; // TODO remove, this is calculated now in connecton let length = 0; - columns.forEach(function(val) { + columns.forEach(val => { if (val === null || typeof val == 'undefined') { ++length; return; @@ -29,7 +29,7 @@ class TextRow { const buffer = Buffer.allocUnsafe(length + 4); const packet = new Packet(sequenceId, buffer, 0, length + 4); packet.offset = 4; - columns.forEach(function(val) { + columns.forEach(val => { if (val === null) { packet.writeNull(); return; diff --git a/lib/pool.js b/lib/pool.js index 7908cac3d9..e769b3964a 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -35,17 +35,13 @@ class Pool extends EventEmitter { getConnection(cb) { if (this._closed) { - return process.nextTick(function() { - return cb(new Error('Pool is closed.')); - }); + return process.nextTick(() => cb(new Error('Pool is closed.'))); } let connection; if (this._freeConnections.length > 0) { connection = this._freeConnections.shift(); this.emit('acquire', connection); - return process.nextTick(function() { - return cb(null, connection); - }); + return process.nextTick(() => cb(null, connection)); } if ( this.config.connectionLimit === 0 || @@ -55,24 +51,20 @@ class Pool extends EventEmitter { config: this.config.connectionConfig }); this._allConnections.push(connection); - return connection.connect( - function(err) { - if (this._closed) { - return cb(new Error('Pool is closed.')); - } - if (err) { - return cb(err); - } - this.emit('connection', connection); - this.emit('acquire', connection); - return cb(null, connection); - }.bind(this) - ); + return connection.connect(err => { + if (this._closed) { + return cb(new Error('Pool is closed.')); + } + if (err) { + return cb(err); + } + this.emit('connection', connection); + this.emit('acquire', connection); + return cb(null, connection); + }); } if (!this.config.waitForConnections) { - return process.nextTick(function() { - return cb(new Error('No connections available.')); - }); + return process.nextTick(() => cb(new Error('No connections available.'))); } if ( this.config.queueLimit && @@ -141,7 +133,7 @@ class Pool extends EventEmitter { this.config.connectionConfig ); cmdQuery.namedPlaceholders = this.config.connectionConfig.namedPlaceholders; - this.getConnection(function(err, conn) { + this.getConnection((err, conn) => { if (err) { if (typeof cmdQuery.onResult === 'function') { cmdQuery.onResult(err); @@ -150,7 +142,7 @@ class Pool extends EventEmitter { } return; } - conn.query(cmdQuery).once('end', function() { + conn.query(cmdQuery).once('end', () => { conn.release(); }); }); @@ -164,12 +156,12 @@ class Pool extends EventEmitter { cb = values; values = []; } - this.getConnection(function(err, conn) { + this.getConnection((err, conn) => { if (err) { return cb(err); } const executeCmd = conn.execute(sql, values, cb); - executeCmd.once('end', function() { + executeCmd.once('end', () => { conn.release(); }); }); diff --git a/lib/pool_cluster.js b/lib/pool_cluster.js index 8db6b02578..465709539b 100644 --- a/lib/pool_cluster.js +++ b/lib/pool_cluster.js @@ -8,23 +8,15 @@ const EventEmitter = require('events').EventEmitter; * Selector */ const makeSelector = { - RR: () => { + RR() { let index = 0; - return clusterIds => { - if (index >= clusterIds.length) { - index = 0; - } - - const clusterId = clusterIds[index++]; - - return clusterId; - }; + return clusterIds => clusterIds[index++ % clusterIds.length]; }, - RANDOM: () => { + RANDOM() { return clusterIds => clusterIds[Math.floor(Math.random() * clusterIds.length)]; }, - ORDER: () => { + ORDER() { return clusterIds => clusterIds[0]; } }; @@ -41,18 +33,15 @@ class PoolNamespace { if (clusterNode === null) { return cb(new Error('Pool does Not exists.')); } - return this._cluster._getConnection( - clusterNode, - function(err, connection) { - if (err) { - return cb(err); - } - if (connection === 'retry') { - return this.getConnection(cb); - } - return cb(null, connection); - }.bind(this) - ); + return this._cluster._getConnection(clusterNode, (err, connection) => { + if (err) { + return cb(err); + } + if (connection === 'retry') { + return this.getConnection(cb); + } + return cb(null, connection); + }); } _getClusterNode() { @@ -153,9 +142,9 @@ class PoolCluster extends EventEmitter { } else { // wild matching const keyword = pattern.substring(pattern.length - 1, 0); - foundNodeIds = this._serviceableNodeIds.filter(function(id) { - return id.indexOf(keyword) === 0; - }); + foundNodeIds = this._serviceableNodeIds.filter( + id => id.indexOf(keyword) === 0 + ); } this._findCaches[pattern] = foundNodeIds; return foundNodeIds; @@ -185,12 +174,12 @@ class PoolCluster extends EventEmitter { } _getConnection(node, cb) { - const self = this; - node.pool.getConnection(function(err, connection) { + node.pool.getConnection((err, connection) => { if (err) { - self._increaseErrorCount(node); - if (self._canRetry) { - self.emit('warn', err); + this._increaseErrorCount(node); + if (this._canRetry) { + // REVIEW: this seems wrong? + this.emit('warn', err); // eslint-disable-next-line no-console console.warn('[Error] PoolCluster : ' + err); return cb(null, 'retry'); @@ -198,7 +187,7 @@ class PoolCluster extends EventEmitter { return cb(err); } } else { - self._decreaseErrorCount(node); + this._decreaseErrorCount(node); } connection._clusterId = node.id; return cb(null, connection); diff --git a/lib/pool_connection.js b/lib/pool_connection.js index ac51c56e2e..be49a73ac9 100644 --- a/lib/pool_connection.js +++ b/lib/pool_connection.js @@ -9,10 +9,11 @@ class PoolConnection extends Connection { // When a fatal error occurs the connection's protocol ends, which will cause // the connection to end as well, thus we only need to watch for the end event // and we will be notified of disconnects. - this.on('end', function() { + // REVIEW: Moved to `once` + this.once('end', () => { this._removeFromPool(); }); - this.on('error', function() { + this.once('error', () => { this._removeFromPool(); }); } @@ -44,7 +45,7 @@ class PoolConnection extends Connection { destroy() { this._removeFromPool(); - return Connection.prototype.destroy.apply(this, arguments); + super.destroy(); } _removeFromPool() { diff --git a/lib/results_stream.js b/lib/results_stream.js index 14dc53b5ba..78fa38cf14 100644 --- a/lib/results_stream.js +++ b/lib/results_stream.js @@ -14,22 +14,22 @@ module.exports = function(command, connectionStream) { connectionStream.resume(); }); - this.on('result', function(row, i) { + this.on('result', (row, i) => { if (!stream.push(row)) { connectionStream.pause(); } stream.emit('result', row, i); // replicate old emitter }); - this.on('error', function(err) { + this.on('error', err => { stream.emit('error', err); // Pass on any errors }); - this.on('end', function() { + this.on('end', () => { stream.push(null); // pushing null, indicating EOF }); - this.on('fields', function(fields, i) { + this.on('fields', (fields, i) => { stream.emit('fields', fields, i); // replicate old emitter }); diff --git a/package-lock.json b/package-lock.json index 271b962930..fcfe6cd5f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,24 +34,21 @@ } }, "acorn": { - "version": "5.7.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", - "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.4.tgz", + "integrity": "sha512-VY4i5EKSKkofY2I+6QLTbTTN/UvEQPCo6eiwzzSaSWfpaDhOmStMCMod6wmuPciNq+XS0faCglFu2lHZpdHUtg==", "dev": true }, "acorn-jsx": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-4.1.1.tgz", - "integrity": "sha512-JY+iV6r+cO21KtntVvFkD+iqjtdpRUpGqKWgfkCdZq1R+kbreEl8EcdcJR4SmiIgsIQT33s6QzheQ9a275Q8xw==", - "dev": true, - "requires": { - "acorn": "^5.0.3" - } + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.0.tgz", + "integrity": "sha512-XkB50fn0MURDyww9+UYL3c1yLbOBz0ZFvrdYlGB8l+Ije1oSC75qAqrzSPjYQbdnQUzhlUGNKuesryAv0gxZOg==", + "dev": true }, "ajv": { - "version": "6.5.4", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.4.tgz", - "integrity": "sha512-4Wyjt8+t6YszqaXnLDfMmG/8AlO5Zbcsy3ATHncCzjW/NoPzAId8AK6749Ybjmdt+kUY1gP60fCu46oDxPv/mg==", + "version": "6.5.5", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.5.tgz", + "integrity": "sha512-7q7gtRQDJSyuEHjuVgHoUa2VuemFiCMrfQc9Tc08XTAc4Zj/5U1buQJ0HU6i7fKjXU09SVgSmxa4sLvuvS8Iyg==", "dev": true, "requires": { "fast-deep-equal": "^2.0.1", @@ -603,7 +600,7 @@ "dependencies": { "pify": { "version": "2.3.0", - "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "dev": true } @@ -678,9 +675,9 @@ "dev": true }, "eslint": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.7.0.tgz", - "integrity": "sha512-zYCeFQahsxffGl87U2aJ7DPyH8CbWgxBC213Y8+TCanhUTf2gEvfq3EKpHmEcozTLyPmGe9LZdMAwC/CpJBM5A==", + "version": "5.8.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.8.0.tgz", + "integrity": "sha512-Zok6Bru3y2JprqTNm14mgQ15YQu/SMDkWdnmHfFg770DIUlmMFd/gqqzCHekxzjHZJxXv3tmTpH0C1icaYJsRQ==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", @@ -772,13 +769,13 @@ "dev": true }, "eslint-plugin-markdown": { - "version": "1.0.0-beta.8", - "resolved": "https://registry.npmjs.org/eslint-plugin-markdown/-/eslint-plugin-markdown-1.0.0-beta.8.tgz", - "integrity": "sha512-prVwlwGQLaBaVGUhSa68KLvZDKc789ezMqY1kbKaGA7KyLN0OW64yBFjnTRRFdWBGx3SQ+BYAvuK2W4dzy9eoA==", + "version": "1.0.0-rc.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-markdown/-/eslint-plugin-markdown-1.0.0-rc.0.tgz", + "integrity": "sha512-28Ioje4p8QAmpxDL91jR4rU+x6+UEx6IW/b+nVnXuS7CMCuOttQl+8BGSu04bm0+8ibOlNsvt5QXc7D847oOkw==", "dev": true, "requires": { "object-assign": "^4.0.1", - "remark-parse": "^3.0.0", + "remark-parse": "^5.0.0", "unified": "^6.1.2" } }, @@ -814,13 +811,14 @@ "dev": true }, "espree": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-4.0.0.tgz", - "integrity": "sha512-kapdTCt1bjmspxStVKX6huolXVV5ZfyZguY1lcfhVVZstce3bqxH9mcLzNn3/mlgW6wQ732+0fuG9v7h0ZQoKg==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-4.1.0.tgz", + "integrity": "sha512-I5BycZW6FCVIub93TeVY1s7vjhP9CY6cXCznIRfiig7nRviKZYdRnj/sHEWC6A7WE9RDWOFq9+7OsWSYz8qv2w==", "dev": true, "requires": { - "acorn": "^5.6.0", - "acorn-jsx": "^4.1.1" + "acorn": "^6.0.2", + "acorn-jsx": "^5.0.0", + "eslint-visitor-keys": "^1.0.0" } }, "esprima": { @@ -1165,12 +1163,6 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, - "function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true - }, "functional-red-black-tree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", @@ -1245,27 +1237,18 @@ "dependencies": { "pify": { "version": "2.3.0", - "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "dev": true } } }, "graceful-fs": { - "version": "4.1.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", - "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", + "version": "4.1.15", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", "dev": true }, - "has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dev": true, - "requires": { - "function-bind": "^1.1.1" - } - }, "has-ansi": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", @@ -1334,9 +1317,9 @@ "dev": true }, "husky": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/husky/-/husky-1.1.2.tgz", - "integrity": "sha512-9TdkUpBeEOjz0AnFdUN4i3w8kEbOsVs9/WSeJqWLq2OO6bcKQhVW64Zi+pVd/AMRLpN3QTINb6ZXiELczvdmqQ==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-1.1.3.tgz", + "integrity": "sha512-6uc48B/A2Mqi65yeg37d/TPcTb0bZ1GTkMYOM0nXLOPuPaTRhXCeee80/noOrbavWd12x72Tusja7GJ5rzvV6g==", "dev": true, "requires": { "cosmiconfig": "^5.0.6", @@ -2172,18 +2155,11 @@ "dev": true }, "named-placeholders": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.1.tgz", - "integrity": "sha1-O3oNJiA910s6nfTJz7gnsvuQfmQ=", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.2.tgz", + "integrity": "sha512-wiFWqxoLL3PGVReSZpjLVxyJ1bRqe+KKJVbr4hGs1KWfTZTQyezHFBbuKj9hsizHyGV2ne7EMjHdxEGAybD5SA==", "requires": { - "lru-cache": "2.5.0" - }, - "dependencies": { - "lru-cache": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.5.0.tgz", - "integrity": "sha1-2COIrpyWC+y+oMc7uet5tsbOmus=" - } + "lru-cache": "^4.1.3" } }, "nanomatch": { @@ -2490,9 +2466,9 @@ "dev": true }, "portfinder": { - "version": "1.0.17", - "resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.17.tgz", - "integrity": "sha512-syFcRIRzVI1BoEFOCaAiizwDolh1S1YXSodsVhncbhjzjZQulhczNRbqnUl9N31Q4dKGOXsNDqxC2BWBgSMqeQ==", + "version": "1.0.19", + "resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.19.tgz", + "integrity": "sha512-23aeQKW9KgHe6citUrG3r9HjeX6vls0h713TAa+CwTKZwNIr/pD2ApaxYF4Um3ZZyq4ar+Siv3+fhoHaIwSOSw==", "dev": true, "requires": { "async": "^1.5.2", @@ -2643,19 +2619,18 @@ "dev": true }, "remark-parse": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/remark-parse/-/remark-parse-3.0.1.tgz", - "integrity": "sha1-G5+EGkTY9PvyJGhQJlRZpOs1TIA=", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/remark-parse/-/remark-parse-5.0.0.tgz", + "integrity": "sha512-b3iXszZLH1TLoyUzrATcTQUZrwNl1rE70rVdSruJFlDaJ9z5aMkhrG43Pp68OgfHndL/ADz6V69Zow8cTQu+JA==", "dev": true, "requires": { "collapse-white-space": "^1.0.2", - "has": "^1.0.1", "is-alphabetical": "^1.0.0", "is-decimal": "^1.0.0", "is-whitespace-character": "^1.0.0", "is-word-character": "^1.0.0", "markdown-escapes": "^1.0.0", - "parse-entities": "^1.0.2", + "parse-entities": "^1.1.0", "repeat-string": "^1.5.4", "state-toggle": "^1.0.0", "trim": "0.0.1", @@ -3016,9 +2991,9 @@ } }, "spdx-license-ids": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.1.tgz", - "integrity": "sha512-TfOfPcYGBB5sDuPn3deByxPhmfegAhpDYKSOXZQN81Oyrrif8ZCodOLzK3AesELnCx03kikhyDwh0pfvvQvF8w==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.2.tgz", + "integrity": "sha512-qky9CVt0lVIECkEsYbNILVnPvycuEBkXoMFLRWsREkomQLevYhtRKC+R91a5TOAQ3bCMjikRwhyaRqj1VYatYg==", "dev": true }, "split-string": { diff --git a/package.json b/package.json index 77dba529f5..11cc020836 100644 --- a/package.json +++ b/package.json @@ -45,27 +45,27 @@ "author": "Andrey Sidorov ", "license": "MIT", "dependencies": { - "denque": "1.4.0", + "denque": "^1.4.0", "generate-function": "^2.3.1", "iconv-lite": "^0.4.24", "long": "^4.0.0", - "lru-cache": "4.1.3", - "named-placeholders": "1.1.1", - "seq-queue": "0.0.5", - "sqlstring": "2.3.1" + "lru-cache": "^4.1.3", + "named-placeholders": "^1.1.2", + "seq-queue": "^0.0.5", + "sqlstring": "^2.3.1" }, "devDependencies": { "assert-diff": "^2.0.2", "error-stack-parser": "^2.0.2", - "eslint": "^5.7.0", + "eslint": "^5.8.0", "eslint-config-prettier": "^3.0.0", "eslint-plugin-async-await": "0.0.0", - "eslint-plugin-markdown": "^1.0.0-beta.8", + "eslint-plugin-markdown": "^1.0.0-rc.0", "eslint-plugin-prettier": "^3.0.0", - "husky": "^1.1.2", + "husky": "^1.1.3", "is-async-supported": "^1.2.0", "lint-staged": "^7.3.0", - "portfinder": "^1.0.17", + "portfinder": "^1.0.19", "prettier": "^1.14.3", "prettier-markdown": "^0.1.6", "progress": "2.0.1", diff --git a/promise.js b/promise.js index 198ece08c5..28257cdd01 100644 --- a/promise.js +++ b/promise.js @@ -21,7 +21,7 @@ function makeDoneCb(resolve, reject, localErr) { function inheritEvents(source, target, events) { const listeners = {}; target - .on('newListener', function(eventName) { + .on('newListener', eventName => { if (events.indexOf(eventName) >= 0 && !target.listenerCount(eventName)) { source.on( eventName, @@ -34,7 +34,7 @@ function inheritEvents(source, target, events) { ); } }) - .on('removeListener', function(eventName) { + .on('removeListener', eventName => { if (events.indexOf(eventName) >= 0 && !target.listenerCount(eventName)) { source.removeListener(eventName, listeners[eventName]); delete listeners[eventName]; @@ -51,7 +51,7 @@ class PromisePreparedStatementInfo { execute(parameters) { const s = this.statement; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { + return new this.Promise((resolve, reject) => { const done = makeDoneCb(resolve, reject, localErr); if (parameters) { s.execute(parameters, done); @@ -90,7 +90,7 @@ class PromiseConnection extends EventEmitter { query(query, params) { const c = this.connection; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { + return new this.Promise((resolve, reject) => { const done = makeDoneCb(resolve, reject, localErr); if (params) { c.query(query, params, done); @@ -103,7 +103,7 @@ class PromiseConnection extends EventEmitter { execute(query, params) { const c = this.connection; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { + return new this.Promise((resolve, reject) => { const done = makeDoneCb(resolve, reject, localErr); if (params) { c.execute(query, params, done); @@ -122,7 +122,7 @@ class PromiseConnection extends EventEmitter { beginTransaction() { const c = this.connection; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { + return new this.Promise((resolve, reject) => { const done = makeDoneCb(resolve, reject, localErr); c.beginTransaction(done); }); @@ -131,7 +131,7 @@ class PromiseConnection extends EventEmitter { commit() { const c = this.connection; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { + return new this.Promise((resolve, reject) => { const done = makeDoneCb(resolve, reject, localErr); c.commit(done); }); @@ -140,7 +140,7 @@ class PromiseConnection extends EventEmitter { rollback() { const c = this.connection; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { + return new this.Promise((resolve, reject) => { const done = makeDoneCb(resolve, reject, localErr); c.rollback(done); }); @@ -149,7 +149,7 @@ class PromiseConnection extends EventEmitter { ping() { const c = this.connection; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { + return new this.Promise((resolve, reject) => { const done = makeDoneCb(resolve, reject, localErr); c.ping(done); }); @@ -158,8 +158,8 @@ class PromiseConnection extends EventEmitter { connect() { const c = this.connection; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { - c.connect(function(err, param) { + return new this.Promise((resolve, reject) => { + c.connect((err, param) => { if (err) { localErr.message = err.message; localErr.code = err.code; @@ -178,8 +178,8 @@ class PromiseConnection extends EventEmitter { const c = this.connection; const promiseImpl = this.Promise; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { - c.prepare(options, function(err, statement) { + return new this.Promise((resolve, reject) => { + c.prepare(options, (err, statement) => { if (err) { localErr.message = err.message; localErr.code = err.code; @@ -201,8 +201,8 @@ class PromiseConnection extends EventEmitter { changeUser(options) { const c = this.connection; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { - c.changeUser(options, function(err) { + return new this.Promise((resolve, reject) => { + c.changeUser(options, err => { if (err) { localErr.message = err.message; localErr.code = err.code; @@ -229,8 +229,8 @@ function createConnection(opts) { " implementation as parameter, for example: { Promise: require('bluebird') }" ); } - return new Promise(function(resolve, reject) { - coreConnection.once('connect', function() { + return new Promise((resolve, reject) => { + coreConnection.once('connect', () => { resolve(new PromiseConnection(coreConnection, Promise)); }); coreConnection.once('error', err => { @@ -305,14 +305,13 @@ class PromisePool extends EventEmitter { } getConnection() { - const self = this; const corePool = this.pool; - return new this.Promise(function(resolve, reject) { - corePool.getConnection(function(err, coreConnection) { + return new this.Promise((resolve, reject) => { + corePool.getConnection((err, coreConnection) => { if (err) { reject(err); } else { - resolve(new PromisePoolConnection(coreConnection, self.Promise)); + resolve(new PromisePoolConnection(coreConnection, this.Promise)); } }); }); @@ -321,7 +320,7 @@ class PromisePool extends EventEmitter { query(sql, args) { const corePool = this.pool; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { + return new this.Promise((resolve, reject) => { const done = makeDoneCb(resolve, reject, localErr); if (args) { corePool.query(sql, args, done); @@ -334,7 +333,7 @@ class PromisePool extends EventEmitter { execute(sql, values) { const corePool = this.pool; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { + return new this.Promise((resolve, reject) => { corePool.execute(sql, values, makeDoneCb(resolve, reject, localErr)); }); } @@ -342,8 +341,8 @@ class PromisePool extends EventEmitter { end() { const corePool = this.pool; const localErr = new Error(); - return new this.Promise(function(resolve, reject) { - corePool.end(function(err) { + return new this.Promise((resolve, reject) => { + corePool.end(err => { if (err) { localErr.message = err.message; localErr.code = err.code; diff --git a/test/common.js b/test/common.js index f03836d1e5..5512d54387 100644 --- a/test/common.js +++ b/test/common.js @@ -25,15 +25,23 @@ module.exports.SqlString = require('sqlstring'); module.exports.config = config; module.exports.waitDatabaseReady = function(callback) { + const start = Date.now(); const tryConnect = function() { const conn = module.exports.createConnection(); - conn.on('error', function(err) { - console.log(err); + conn.once('error', err => { + if (err.code !== 'PROTOCOL_CONNECTION_LOST' && err.code !== 'ETIMEDOUT') { + console.log('Unexpected error waiting for connection', err); + } + try { + conn.close(); + } catch (err) { + // ignore + } console.log('not ready'); setTimeout(tryConnect, 1000); }); - conn.on('connect', function() { - console.log('ready!'); + conn.once('connect', () => { + console.log(`ready after ${Date.now() - start}ms!`); conn.close(); callback(); }); @@ -70,17 +78,17 @@ module.exports.createConnection = function(args) { // c.on('connect', function() { // // }); - setTimeout(function() { + setTimeout(() => { console.log('altering client...'); c.oldQuery = c.query; c.query = function(sql, callback) { const rows = []; const q = c.oldQuery(sql); - q.on('result', function(res) { - res.on('row', function(row) { + q.on('result', res => { + res.on('row', row => { rows.push(row); }); - res.on('end', function() { + res.on('end', () => { callback(null, rows); }); }); @@ -183,8 +191,8 @@ const ClientFlags = require('../lib/constants/client.js'); const portfinder = require('portfinder'); module.exports.createServer = function(onListening, handler) { const server = require('../index.js').createServer(); - server.on('connection', function(conn) { - conn.on('error', function() { + server.on('connection', conn => { + conn.on('error', () => { // we are here when client drops connection }); let flags = 0xffffff; @@ -202,7 +210,7 @@ module.exports.createServer = function(onListening, handler) { handler(conn); } }); - portfinder.getPort(function(err, port) { + portfinder.getPort((err, port) => { server.listen(port, onListening); }); return server; diff --git a/test/integration/config/test-connect-timeout.js b/test/integration/config/test-connect-timeout.js index d081b9ee5e..572ef660ff 100644 --- a/test/integration/config/test-connect-timeout.js +++ b/test/integration/config/test-connect-timeout.js @@ -9,12 +9,12 @@ const assert = require('assert'); let errorCount = 0; let error = null; -connection.on('error', function(err) { +connection.on('error', err => { errorCount++; error = err; }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(errorCount, 1); assert.equal(error.code, 'ETIMEDOUT'); }); diff --git a/test/integration/config/test-typecast-global-option.js b/test/integration/config/test-typecast-global-option.js index 9de3989ceb..4a8c346e7a 100644 --- a/test/integration/config/test-typecast-global-option.js +++ b/test/integration/config/test-typecast-global-option.js @@ -22,7 +22,7 @@ connection.query( sql: 'select "FOOBAR" as foo', typeCast: typeCastWrapper('toLowerCase') }, - function(err, res) { + (err, res) => { assert.ifError(err); assert.equal(res[0].foo, 'foobar'); } @@ -33,7 +33,7 @@ connection.query( { sql: 'select "foobar" as foo' }, - function(err, res) { + (err, res) => { assert.ifError(err); assert.equal(res[0].foo, 'FOOBAR'); } diff --git a/test/integration/connection/encoding/test-charset-results.js b/test/integration/connection/encoding/test-charset-results.js index 1f0d20ed09..bdade0f15a 100644 --- a/test/integration/connection/encoding/test-charset-results.js +++ b/test/integration/connection/encoding/test-charset-results.js @@ -8,9 +8,9 @@ const assert = require('assert'); const payload = 'привет, мир'; function tryEncoding(encoding, cb) { - connection.query('set character_set_results = ?', [encoding], function(err) { + connection.query('set character_set_results = ?', [encoding], err => { assert.ifError(err); - connection.query('SELECT ?', [payload], function(err, rows, fields) { + connection.query('SELECT ?', [payload], (err, rows, fields) => { assert.ifError(err); let iconvEncoding = encoding; if (encoding == 'utf8mb4') { @@ -28,11 +28,9 @@ function tryEncoding(encoding, cb) { } function tryEncodingExecute(encoding, cb) { - connection.execute('set character_set_results = ?', [encoding], function( - err - ) { + connection.execute('set character_set_results = ?', [encoding], err => { assert.ifError(err); - connection.execute('SELECT ? as n', [payload], function(err, rows, fields) { + connection.execute('SELECT ? as n', [payload], (err, rows, fields) => { assert.ifError(err); let iconvEncoding = encoding; if (encoding == 'utf8mb4') { @@ -51,14 +49,14 @@ function tryEncodingExecute(encoding, cb) { } // christmas tree!!! :) -tryEncoding('cp1251', function() { - tryEncoding('koi8r', function() { - tryEncoding('cp866', function() { - tryEncoding('utf8mb4', function() { - tryEncodingExecute('cp1251', function() { - tryEncodingExecute('koi8r', function() { - tryEncodingExecute('cp866', function() { - tryEncodingExecute('utf8mb4', function() { +tryEncoding('cp1251', () => { + tryEncoding('koi8r', () => { + tryEncoding('cp866', () => { + tryEncoding('utf8mb4', () => { + tryEncodingExecute('cp1251', () => { + tryEncodingExecute('koi8r', () => { + tryEncodingExecute('cp866', () => { + tryEncodingExecute('utf8mb4', () => { connection.end(); }); }); diff --git a/test/integration/connection/encoding/test-client-encodings.js b/test/integration/connection/encoding/test-client-encodings.js index 857c4ef81c..b4df96fc56 100644 --- a/test/integration/connection/encoding/test-client-encodings.js +++ b/test/integration/connection/encoding/test-client-encodings.js @@ -7,9 +7,9 @@ const connection = common.createConnection({ charset: 'UTF8MB4_GENERAL_CI' }); connection.query('drop table if exists __test_client_encodings'); connection.query( 'create table if not exists __test_client_encodings (name VARCHAR(200)) CHARACTER SET=utf8mb4', - function(err) { + err => { assert.ifError(err); - connection.query('delete from __test_client_encodings', function(err) { + connection.query('delete from __test_client_encodings', err => { assert.ifError(err); connection.end(); @@ -18,21 +18,21 @@ connection.query( }); connection1.query( 'insert into __test_client_encodings values("привет, мир")', - function(err) { + err => { assert.ifError(err); connection1.end(); const connection2 = common.createConnection({ charset: 'KOI8R_GENERAL_CI' }); - connection2.query('select * from __test_client_encodings', function( - err, - rows - ) { - assert.ifError(err); - assert.equal(rows[0].name, 'привет, мир'); - connection2.end(); - }); + connection2.query( + 'select * from __test_client_encodings', + (err, rows) => { + assert.ifError(err); + assert.equal(rows[0].name, 'привет, мир'); + connection2.end(); + } + ); } ); }); diff --git a/test/integration/connection/encoding/test-non-bmp-chars.js b/test/integration/connection/encoding/test-non-bmp-chars.js index 1d6e157d9d..7dcf0abbe4 100644 --- a/test/integration/connection/encoding/test-non-bmp-chars.js +++ b/test/integration/connection/encoding/test-non-bmp-chars.js @@ -7,7 +7,7 @@ const assert = require('assert'); const pileOfPoo = '💩'; const connection = common.createConnection({ charset: 'UTF8_GENERAL_CI' }); -connection.query('select "💩"', function(err, rows, fields) { +connection.query('select "💩"', (err, rows, fields) => { assert.ifError(err); assert.equal(fields[0].name, pileOfPoo); assert.equal(rows[0][fields[0].name], pileOfPoo); @@ -15,7 +15,7 @@ connection.query('select "💩"', function(err, rows, fields) { }); const connection2 = common.createConnection({ charset: 'UTF8MB4_GENERAL_CI' }); -connection2.query('select "💩"', function(err, rows, fields) { +connection2.query('select "💩"', (err, rows, fields) => { assert.ifError(err); assert.equal(fields[0].name, '?'); assert.equal(rows[0]['?'], pileOfPoo); diff --git a/test/integration/connection/encoding/test-track-encodings.js b/test/integration/connection/encoding/test-track-encodings.js index 69b0477322..88135b3944 100644 --- a/test/integration/connection/encoding/test-track-encodings.js +++ b/test/integration/connection/encoding/test-track-encodings.js @@ -6,14 +6,14 @@ const assert = require('assert'); const connection = common.createConnection({ charset: 'UTF8MB4_GENERAL_CI' }); const text = 'привет, мир'; -connection.query('SET character_set_client=koi8r', function(err) { +connection.query('SET character_set_client=koi8r', err => { assert.ifError(err); - connection.query('SELECT ?', [text], function(err, rows) { + connection.query('SELECT ?', [text], (err, rows) => { assert.ifError(err); assert.equal(rows[0][text], text); - connection.query('SET character_set_client=cp1251', function(err) { + connection.query('SET character_set_client=cp1251', err => { assert.ifError(err); - connection.query('SELECT ?', [text], function(err, rows) { + connection.query('SELECT ?', [text], (err, rows) => { assert.ifError(err); assert.equal(rows[0][text], text); connection.end(); diff --git a/test/integration/connection/test-binary-charset-string.js b/test/integration/connection/test-binary-charset-string.js index 2b4e3e9602..57d546cf40 100644 --- a/test/integration/connection/test-binary-charset-string.js +++ b/test/integration/connection/test-binary-charset-string.js @@ -21,7 +21,7 @@ let fields5 = undefined; const query = "SELECT x'010203'"; const query1 = "SELECT '010203'"; -connection.query(query, function(err, _rows, _fields) { +connection.query(query, (err, _rows, _fields) => { if (err) { throw err; } @@ -29,7 +29,7 @@ connection.query(query, function(err, _rows, _fields) { fields = _fields; }); -connection.query(query, function(err, _rows, _fields) { +connection.query(query, (err, _rows, _fields) => { if (err) { throw err; } @@ -37,7 +37,7 @@ connection.query(query, function(err, _rows, _fields) { fields5 = _fields; }); -connection.query(query1, function(err, _rows, _fields) { +connection.query(query1, (err, _rows, _fields) => { if (err) { throw err; } @@ -45,7 +45,7 @@ connection.query(query1, function(err, _rows, _fields) { fields1 = _fields; }); -connection.execute(query, [], function(err, _rows, _fields) { +connection.execute(query, [], (err, _rows, _fields) => { if (err) { throw err; } @@ -54,7 +54,7 @@ connection.execute(query, [], function(err, _rows, _fields) { }); // repeat same query - test cached fields and parser -connection.execute(query, [], function(err, _rows, _fields) { +connection.execute(query, [], (err, _rows, _fields) => { if (err) { throw err; } @@ -62,7 +62,7 @@ connection.execute(query, [], function(err, _rows, _fields) { fields4 = _fields; }); -connection.execute(query1, [], function(err, _rows, _fields) { +connection.execute(query1, [], (err, _rows, _fields) => { if (err) { throw err; } @@ -71,7 +71,7 @@ connection.execute(query1, [], function(err, _rows, _fields) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ "x'010203'": Buffer.from([1, 2, 3]) }]); assert.equal(fields[0].name, "x'010203'"); assert.deepEqual(rows1, [{ '010203': '010203' }]); diff --git a/test/integration/connection/test-binary-longlong.js b/test/integration/connection/test-binary-longlong.js index d7e2baa5bd..5ae028545b 100644 --- a/test/integration/connection/test-binary-longlong.js +++ b/test/integration/connection/test-binary-longlong.js @@ -22,7 +22,7 @@ const values = [ [null, null] ]; -conn.connect(function(err) { +conn.connect(err => { if (err) { console.error(err); return; @@ -71,7 +71,7 @@ conn.connect(function(err) { supportBigNumbers: supportBigNumbers, bigNumberStrings: bigNumberStrings }, - function(err, rows) { + (err, rows) => { assert.ifError(err); assert.deepEqual(rows, expectation); completed++; @@ -90,7 +90,7 @@ conn.connect(function(err) { supportBigNumbers: supportBigNumbers, bigNumberStrings: bigNumberStrings }, - function(err, rows) { + (err, rows) => { assert.ifError(err); assert.deepEqual(rows, expectation); completed++; diff --git a/test/integration/connection/test-binary-multiple-results.js b/test/integration/connection/test-binary-multiple-results.js index 305eca83b0..3af62906b2 100644 --- a/test/integration/connection/test-binary-multiple-results.js +++ b/test/integration/connection/test-binary-multiple-results.js @@ -119,14 +119,14 @@ function do_test(testIndex) { const expectation = entry[1]; // prepared statements do not support multiple statements itself, we need to wrap quey in a stored procedure const sp = procedurise(sql); - mysql.query(sp, function(err) { + mysql.query(sp, err => { if (err) { throw err; } sql = 'CALL _as_sp_call()'; // this call is allowed with prepared statements, and result contain multiple statements let _numResults = 0; - const textCmd = mysql.query(sql, function(err, _rows, _columns) { + const textCmd = mysql.query(sql, (err, _rows, _columns) => { if (err) { throw err; } @@ -190,7 +190,7 @@ function do_test(testIndex) { q.on('end', next); }); - textCmd.on('fields', function() { + textCmd.on('fields', () => { _numResults++; }); }); diff --git a/test/integration/connection/test-binary-notnull-nulls.js b/test/integration/connection/test-binary-notnull-nulls.js index 67b2fd835f..97f48ec4ae 100644 --- a/test/integration/connection/test-binary-notnull-nulls.js +++ b/test/integration/connection/test-binary-notnull-nulls.js @@ -47,7 +47,7 @@ conn.query( "INSERT INTO `tmp_account_session` VALUES ('1', '::1', '75efb145482ce22f4544390cad233c749c1b43e4', '1')" ); -conn.connect(function(err) { +conn.connect(err => { if (err) { console.error(err); return; @@ -56,7 +56,7 @@ conn.connect(function(err) { conn.execute( "SELECT `ac`.`username`, CONCAT('[', GROUP_CONCAT(DISTINCT `acf`.`flag` SEPARATOR ','), ']') flags FROM tmp_account ac LEFT JOIN tmp_account_flags acf ON `acf`.account = `ac`.id LEFT JOIN tmp_account_session acs ON `acs`.account = `ac`.id WHERE `acs`.`session`=?", ['asid=75efb145482ce22f4544390cad233c749c1b43e4'], - function(err, rows, fields) { + (err, rows, fields) => { const flagNotNull = fields[0].flags & FieldFlags.NOT_NULL; const valueIsNull = rows[0][fields[0].name] === null; assert(flagNotNull && valueIsNull); diff --git a/test/integration/connection/test-buffer-params.js b/test/integration/connection/test-buffer-params.js index f34010933c..8f3b7172f5 100644 --- a/test/integration/connection/test-buffer-params.js +++ b/test/integration/connection/test-buffer-params.js @@ -24,14 +24,14 @@ const buf = Buffer.from([ 255, 255 ]); -connection.execute('SELECT HEX(?) as buf', [buf], function(err, _rows) { +connection.execute('SELECT HEX(?) as buf', [buf], (err, _rows) => { if (err) { throw err; } rows = _rows; }); -connection.query('SELECT HEX(?) as buf', [buf], function(err, _rows) { +connection.query('SELECT HEX(?) as buf', [buf], (err, _rows) => { if (err) { throw err; } @@ -39,7 +39,7 @@ connection.query('SELECT HEX(?) as buf', [buf], function(err, _rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ buf: buf.toString('hex').toUpperCase() }]); assert.deepEqual(rows1, [{ buf: buf.toString('hex').toUpperCase() }]); }); diff --git a/test/integration/connection/test-change-user-plugin-auth.js b/test/integration/connection/test-change-user-plugin-auth.js index ee1052f76a..5e16b71686 100644 --- a/test/integration/connection/test-change-user-plugin-auth.js +++ b/test/integration/connection/test-change-user-plugin-auth.js @@ -45,9 +45,9 @@ connection.changeUser( user: 'changeuser1', password: 'changeuser1pass' }, - function(err) { + err => { assert.ifError(err); - connection.query('select current_user()', function(err, rows) { + connection.query('select current_user()', (err, rows) => { assert.ifError(err); assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser1'); @@ -56,10 +56,10 @@ connection.changeUser( user: 'changeuser2', password: 'changeuser2pass' }, - function(err) { + err => { assert.ifError(err); - connection.query('select current_user()', function(err, rows) { + connection.query('select current_user()', (err, rows) => { assert.ifError(err); assert.deepEqual( onlyUsername(rows[0]['current_user()']), @@ -74,8 +74,8 @@ connection.changeUser( 'hex' ) // sha1(changeuser1pass) }, - function() { - connection.query('select current_user()', function(err, rows) { + () => { + connection.query('select current_user()', (err, rows) => { assert.ifError(err); assert.deepEqual( onlyUsername(rows[0]['current_user()']), diff --git a/test/integration/connection/test-change-user.js b/test/integration/connection/test-change-user.js index 73c0ca78ff..490e52b17b 100644 --- a/test/integration/connection/test-change-user.js +++ b/test/integration/connection/test-change-user.js @@ -38,9 +38,9 @@ connection.changeUser( user: 'changeuser1', password: 'changeuser1pass' }, - function(err) { + err => { assert.ifError(err); - connection.query('select current_user()', function(err, rows) { + connection.query('select current_user()', (err, rows) => { assert.ifError(err); assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser1'); @@ -49,10 +49,10 @@ connection.changeUser( user: 'changeuser2', password: 'changeuser2pass' }, - function(err) { + err => { assert.ifError(err); - connection.query('select current_user()', function(err, rows) { + connection.query('select current_user()', (err, rows) => { assert.ifError(err); assert.deepEqual( onlyUsername(rows[0]['current_user()']), @@ -67,8 +67,8 @@ connection.changeUser( 'hex' ) // sha1(changeuser1pass) }, - function() { - connection.query('select current_user()', function(err, rows) { + () => { + connection.query('select current_user()', (err, rows) => { assert.ifError(err); assert.deepEqual( onlyUsername(rows[0]['current_user()']), diff --git a/test/integration/connection/test-charset-encoding.js b/test/integration/connection/test-charset-encoding.js index 931c324f8a..1db90d24c1 100644 --- a/test/integration/connection/test-charset-encoding.js +++ b/test/integration/connection/test-charset-encoding.js @@ -20,20 +20,17 @@ let resultData = null; const testEncoding = function(err) { assert.ifError(err); - testData.forEach(function(data) { + testData.forEach(data => { connection.query( 'INSERT INTO `test-charset-encoding` (field) values(?)', [data], - function(err2) { + err2 => { assert.ifError(err2); } ); }); - connection.query('SELECT * from `test-charset-encoding`', function( - err, - results - ) { + connection.query('SELECT * from `test-charset-encoding`', (err, results) => { assert.ifError(err); resultData = results; }); @@ -42,11 +39,11 @@ const testEncoding = function(err) { // init test sequence (function() { - connection.query('DROP TABLE IF EXISTS `test-charset-encoding`', function() { + connection.query('DROP TABLE IF EXISTS `test-charset-encoding`', () => { connection.query( 'CREATE TABLE IF NOT EXISTS `test-charset-encoding` ' + '( `field` VARCHAR(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci)', - function(err) { + err => { assert.ifError(err); connection.query('DELETE from `test-charset-encoding`', testEncoding); } @@ -54,8 +51,8 @@ const testEncoding = function(err) { }); })(); -process.on('exit', function() { - resultData.forEach(function(data, index) { +process.on('exit', () => { + resultData.forEach((data, index) => { assert.equal(data.field, testData[index]); }); }); diff --git a/test/integration/connection/test-connect-sha1.js b/test/integration/connection/test-connect-sha1.js index 63f0bcf128..4372c6221e 100644 --- a/test/integration/connection/test-connect-sha1.js +++ b/test/integration/connection/test-connect-sha1.js @@ -22,10 +22,10 @@ let _1_3 = false; let queryCalls = 0; const portfinder = require('portfinder'); -portfinder.getPort(function(err, port) { +portfinder.getPort((err, port) => { const server = mysql.createServer(); server.listen(port); - server.on('connection', function(conn) { + server.on('connection', conn => { conn.serverHandshake({ protocolVersion: 10, serverVersion: 'node.js rocks', @@ -35,7 +35,7 @@ portfinder.getPort(function(err, port) { capabilityFlags: 0xffffff, authCallback: authenticate }); - conn.on('query', function(sql) { + conn.on('query', sql => { assert.equal(sql, 'select 1+1'); queryCalls++; conn.close(); @@ -49,27 +49,27 @@ portfinder.getPort(function(err, port) { passwordSha1: Buffer.from('8bb6118f8fd6935ad0876a3be34a717d32708ffd', 'hex') }); - connection.on('error', function(err) { + connection.on('error', err => { assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); }); - connection.query('select 1+1', function(err) { + connection.query('select 1+1', err => { assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); server._server.close(); }); - connection.query('select 1+2', function(err) { + connection.query('select 1+2', err => { assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); _1_2 = true; }); - connection.query('select 1+3', function(err) { + connection.query('select 1+3', err => { assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); _1_3 = true; }); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(queryCalls, 1); assert.equal(_1_2, true); assert.equal(_1_3, true); diff --git a/test/integration/connection/test-connect-time-error.js b/test/integration/connection/test-connect-time-error.js index 1d18079e2e..48fe86dcc5 100644 --- a/test/integration/connection/test-connect-time-error.js +++ b/test/integration/connection/test-connect-time-error.js @@ -6,10 +6,10 @@ const assert = require('assert'); const ERROR_TEXT = 'test error'; const portfinder = require('portfinder'); -portfinder.getPort(function(err, port) { +portfinder.getPort((err, port) => { const server = mysql.createServer(); server.listen(port); - server.on('connection', function(conn) { + server.on('connection', conn => { console.log('Here!'); conn.writeError(new Error(ERROR_TEXT)); conn.close(); @@ -23,11 +23,11 @@ portfinder.getPort(function(err, port) { password: 'testpassword' }); - connection.query('select 1+1', function(err) { + connection.query('select 1+1', err => { assert.equal(err.message, ERROR_TEXT); }); - connection.query('select 1+2', function(err) { + connection.query('select 1+2', err => { assert.equal(err.message, ERROR_TEXT); connection.close(); server._server.close(); diff --git a/test/integration/connection/test-connect-with-uri.js b/test/integration/connection/test-connect-with-uri.js index 2981169520..1af14948e9 100644 --- a/test/integration/connection/test-connect-with-uri.js +++ b/test/integration/connection/test-connect-with-uri.js @@ -6,7 +6,7 @@ const assert = require('assert'); let rows = undefined; let fields = undefined; -connection.query('SELECT 1', function(err, _rows, _fields) { +connection.query('SELECT 1', (err, _rows, _fields) => { if (err) { throw err; } @@ -16,7 +16,7 @@ connection.query('SELECT 1', function(err, _rows, _fields) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ 1: 1 }]); assert.equal(fields[0].name, '1'); }); diff --git a/test/integration/connection/test-custom-date-parameter.js b/test/integration/connection/test-custom-date-parameter.js index 603776072e..b3a828a569 100644 --- a/test/integration/connection/test-custom-date-parameter.js +++ b/test/integration/connection/test-custom-date-parameter.js @@ -20,7 +20,7 @@ connection.query("set time_zone = '+00:00'"); connection.execute( 'SELECT UNIX_TIMESTAMP(?) t', [new Date('1990-08-08 UTC')], - function(err, _rows) { + (err, _rows) => { if (err) { throw err; } @@ -29,6 +29,6 @@ connection.execute( } ); -process.on('exit', function() { +process.on('exit', () => { assert.equal(rows[0].t, 650073600); }); diff --git a/test/integration/connection/test-date-parameter.js b/test/integration/connection/test-date-parameter.js index ece678343e..48bb08a8f3 100644 --- a/test/integration/connection/test-date-parameter.js +++ b/test/integration/connection/test-date-parameter.js @@ -10,7 +10,7 @@ connection.query("set time_zone = '+00:00'"); connection.execute( 'SELECT UNIX_TIMESTAMP(?) t', [new Date('1990-01-01 UTC')], - function(err, _rows) { + (err, _rows) => { if (err) { throw err; } @@ -19,6 +19,6 @@ connection.execute( } ); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ t: 631152000 }]); }); diff --git a/test/integration/connection/test-datetime.js b/test/integration/connection/test-datetime.js index d02a3c48f4..a7051554b3 100644 --- a/test/integration/connection/test-datetime.js +++ b/test/integration/connection/test-datetime.js @@ -52,7 +52,7 @@ const dateAsStringExpected = [ connection.execute( 'select from_unixtime(?) t', [(+date).valueOf() / 1000], - function(err, _rows) { + (err, _rows) => { if (err) { throw err; } @@ -60,21 +60,21 @@ connection.execute( } ); -connection.query('select from_unixtime(631152000) t', function(err, _rows) { +connection.query('select from_unixtime(631152000) t', (err, _rows) => { if (err) { throw err; } rows1 = _rows; }); -connection.query('select * from t', function(err, _rows) { +connection.query('select * from t', (err, _rows) => { if (err) { throw err; } rows2 = _rows; }); -connection.execute('select * from t', function(err, _rows) { +connection.execute('select * from t', (err, _rows) => { if (err) { throw err; } @@ -82,32 +82,33 @@ connection.execute('select * from t', function(err, _rows) { connection.end(); }); -connection1.query('select * from t', function(err, _rows) { +connection1.query('select * from t', (err, _rows) => { if (err) { throw err; } rows4 = _rows; }); -connection1.execute('select * from t', function(err, _rows) { +connection1.execute('select * from t', (err, _rows) => { if (err) { throw err; } rows5 = _rows; }); -connection1.execute('select * from t where d6 = ?', [new Date(date5)], function( - err, - _rows -) { - if (err) { - throw err; +connection1.execute( + 'select * from t where d6 = ?', + [new Date(date5)], + (err, _rows) => { + if (err) { + throw err; + } + rows6 = _rows; + connection1.end(); } - rows6 = _rows; - connection1.end(); -}); +); -process.on('exit', function() { +process.on('exit', () => { assert.equal(rows[0].t.constructor, Date); assert.equal(rows[0].t.getDate(), date.getDate()); assert.equal(rows[0].t.getHours(), date.getHours()); diff --git a/test/integration/connection/test-decimals-as-numbers.js b/test/integration/connection/test-decimals-as-numbers.js index d0fc9d536a..8a8c6b361c 100644 --- a/test/integration/connection/test-decimals-as-numbers.js +++ b/test/integration/connection/test-decimals-as-numbers.js @@ -20,7 +20,7 @@ connection1.query('INSERT INTO t1 set d1=?', [largeDecimal]); connection2.query('CREATE TEMPORARY TABLE t2 (d1 DECIMAL(14, 2))'); connection2.query('INSERT INTO t2 set d1=?', [largeMoneyValue]); -connection1.execute('select d1 from t1', function(err, _rows) { +connection1.execute('select d1 from t1', (err, _rows) => { if (err) { throw err; } @@ -29,7 +29,7 @@ connection1.execute('select d1 from t1', function(err, _rows) { connection1.end(); }); -connection2.query('select d1 from t2', function(err, _rows) { +connection2.query('select d1 from t2', (err, _rows) => { if (err) { throw err; } diff --git a/test/integration/connection/test-disconnects.js b/test/integration/connection/test-disconnects.js index 20262eafd7..3acb4c685b 100644 --- a/test/integration/connection/test-disconnects.js +++ b/test/integration/connection/test-disconnects.js @@ -11,21 +11,21 @@ const connections = []; const server = common.createServer( () => { const connection = common.createConnection({ port: server._port }); - connection.query('SELECT 123', function(err, _rows, _fields) { + connection.query('SELECT 123', (err, _rows, _fields) => { if (err) { throw err; } rows = _rows; fields = _fields; - connection.on('error', function(_err) { + connection.on('error', _err => { err = _err; }); - connections.forEach(function(conn) { + connections.forEach(conn => { conn.stream.end(); }); - server._server.close(function() { + server._server.close(() => { assert.equal(err.code, 'PROTOCOL_CONNECTION_LOST'); }); }); @@ -33,7 +33,7 @@ const server = common.createServer( }, conn => { connections.push(conn); - conn.on('query', function() { + conn.on('query', () => { conn.writeTextResult( [{ '1': '1' }], [ @@ -56,7 +56,7 @@ const server = common.createServer( } ); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ 1: 1 }]); assert.equal(fields[0].name, '1'); }); diff --git a/test/integration/connection/test-error-events.js b/test/integration/connection/test-error-events.js index ab1a236dbb..87f0d1d64c 100644 --- a/test/integration/connection/test-error-events.js +++ b/test/integration/connection/test-error-events.js @@ -6,7 +6,7 @@ const assert = require('assert'); let callCount = 0; let exceptionCount = 0; -process.on('uncaughtException', function(err) { +process.on('uncaughtException', err => { assert.ifError(err); exceptionCount++; }); @@ -16,7 +16,7 @@ const connection1 = common.createConnection({ }); // error will NOT bubble up to process level if `on` is used -connection1.on('error', function() { +connection1.on('error', () => { callCount++; }); @@ -25,11 +25,11 @@ const connection2 = common.createConnection({ }); // error will bubble up to process level if `once` is used -connection2.once('error', function() { +connection2.once('error', () => { callCount++; }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(callCount, 2); assert.equal(exceptionCount, 0); }); diff --git a/test/integration/connection/test-errors.js b/test/integration/connection/test-errors.js index 8210d49fe5..a51dec3089 100644 --- a/test/integration/connection/test-errors.js +++ b/test/integration/connection/test-errors.js @@ -12,36 +12,36 @@ let onExecuteErrorEvent1 = undefined; let onQueryErrorEvent1 = undefined; connection - .execute('error in execute', [], function(err) { + .execute('error in execute', [], err => { assert.equal(err.errno, 1064); assert.equal(err.code, 'ER_PARSE_ERROR'); if (err) { onExecuteResultError = true; } }) - .on('error', function() { + .on('error', () => { onExecuteErrorEvent = true; }); connection - .query('error in query', [], function(err) { + .query('error in query', [], err => { assert.equal(err.errno, 1064); assert.equal(err.code, 'ER_PARSE_ERROR'); if (err) { onQueryResultError = true; } }) - .on('error', function() { + .on('error', () => { onQueryErrorEvent = true; }); -connection.execute('error in execute 1', []).on('error', function() { +connection.execute('error in execute 1', []).on('error', () => { onExecuteErrorEvent1 = true; }); -connection.query('error in query 1').on('error', function() { +connection.query('error in query 1').on('error', () => { onQueryErrorEvent1 = true; connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(onExecuteResultError, true); assert.equal(onQueryResultError, true); assert.equal(onExecuteErrorEvent, undefined); diff --git a/test/integration/connection/test-execute-1.js b/test/integration/connection/test-execute-1.js index ff1ba159d8..6e73758e34 100644 --- a/test/integration/connection/test-execute-1.js +++ b/test/integration/connection/test-execute-1.js @@ -17,14 +17,14 @@ connection.query( 'PRIMARY KEY (`id`)', ') ENGINE=InnoDB DEFAULT CHARSET=utf8' ].join('\n'), - function(err) { + err => { if (err) { throw err; } } ); -connection.execute('SELECT 1+? as test', [123], function(err, _rows, _fields) { +connection.execute('SELECT 1+? as test', [123], (err, _rows, _fields) => { if (err) { throw err; } @@ -32,7 +32,7 @@ connection.execute('SELECT 1+? as test', [123], function(err, _rows, _fields) { rows = _rows; fields = _fields; }); -connection.execute('SELECT 1 as test', function(err, _rows, _fields) { +connection.execute('SELECT 1 as test', (err, _rows, _fields) => { if (err) { throw err; } @@ -44,7 +44,7 @@ connection.execute('SELECT 1 as test', function(err, _rows, _fields) { connection.execute( 'INSERT INTO announcements(title, text) VALUES(?, ?)', ['Есть место, где заканчивается тротуар', 'Расти борода, расти'], - function(err) { + err => { if (err) { throw err; } @@ -56,13 +56,13 @@ connection.execute( 'Граждане Российской Федерации имеют право собираться мирно без оружия', 'проводить собрания, митинги и демонстрации, шествия и пикетирование' ], - function(err) { + err => { if (err) { throw err; } } ); -connection.execute('SELECT * FROM announcements', function(err, rows) { +connection.execute('SELECT * FROM announcements', (err, rows) => { if (err) { throw err; } @@ -81,7 +81,7 @@ connection.execute('SELECT * FROM announcements', function(err, rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ test: 124 }]); assert.deepEqual(rows1, [{ test: 1 }]); assert.equal(fields[0].name, 'test'); diff --git a/test/integration/connection/test-execute-and-unprepare.js b/test/integration/connection/test-execute-and-unprepare.js index 15eca6d445..91a6c0e25c 100644 --- a/test/integration/connection/test-execute-and-unprepare.js +++ b/test/integration/connection/test-execute-and-unprepare.js @@ -6,7 +6,7 @@ const connection = common.createConnection(); const max = 500; function exec(i) { const query = 'select 1+' + i; - connection.execute(query, function(err) { + connection.execute(query, err => { connection.unprepare(query); if (err) { throw err; @@ -18,7 +18,7 @@ function exec(i) { } }); } -connection.query('SET GLOBAL max_prepared_stmt_count=10', function(err) { +connection.query('SET GLOBAL max_prepared_stmt_count=10', err => { if (err) { throw err; } diff --git a/test/integration/connection/test-execute-bind-boolean.js b/test/integration/connection/test-execute-bind-boolean.js index 615322cee8..39ec561803 100644 --- a/test/integration/connection/test-execute-bind-boolean.js +++ b/test/integration/connection/test-execute-bind-boolean.js @@ -8,7 +8,7 @@ let rows; connection.execute( 'SELECT ? AS trueValue, ? AS falseValue', [true, false], - function(err, _rows) { + (err, _rows) => { if (err) { throw err; } @@ -17,6 +17,6 @@ connection.execute( } ); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ trueValue: 1, falseValue: 0 }]); }); diff --git a/test/integration/connection/test-execute-bind-date.js b/test/integration/connection/test-execute-bind-date.js index ae672d933a..d98e58ce5b 100644 --- a/test/integration/connection/test-execute-bind-date.js +++ b/test/integration/connection/test-execute-bind-date.js @@ -7,7 +7,7 @@ const assert = require('assert'); const date = new Date(2018, 2, 10, 15, 12, 34, 1234); let rows; -connection.execute('SELECT ? AS result', [date], function(err, _rows) { +connection.execute('SELECT ? AS result', [date], (err, _rows) => { if (err) { throw err; } @@ -15,6 +15,6 @@ connection.execute('SELECT ? AS result', [date], function(err, _rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ result: date }]); }); diff --git a/test/integration/connection/test-execute-bind-function.js b/test/integration/connection/test-execute-bind-function.js index 4cf84f75ab..2c057d528d 100644 --- a/test/integration/connection/test-execute-bind-function.js +++ b/test/integration/connection/test-execute-bind-function.js @@ -7,13 +7,13 @@ const assert = require('assert'); let error = null; try { - connection.execute('SELECT ? AS result', [function() {}], function() {}); + connection.execute('SELECT ? AS result', [function() {}], () => {}); } catch (err) { error = err; connection.end(); } -process.on('exit', function() { +process.on('exit', () => { assert.equal(error.name, 'TypeError'); if (!error.message.match(/function/)) { assert.fail("Expected error.message to contain 'function'"); diff --git a/test/integration/connection/test-execute-bind-json.js b/test/integration/connection/test-execute-bind-json.js index a80498d544..77240bcad8 100644 --- a/test/integration/connection/test-execute-bind-json.js +++ b/test/integration/connection/test-execute-bind-json.js @@ -8,7 +8,7 @@ let rows; connection.execute( 'SELECT ? AS result', [{ a: 1, b: true, c: ['foo'] }], - function(err, _rows) { + (err, _rows) => { if (err) { throw err; } @@ -17,6 +17,6 @@ connection.execute( } ); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ result: { a: 1, b: true, c: ['foo'] } }]); }); diff --git a/test/integration/connection/test-execute-bind-null.js b/test/integration/connection/test-execute-bind-null.js index 96274262b8..7af88b60fe 100644 --- a/test/integration/connection/test-execute-bind-null.js +++ b/test/integration/connection/test-execute-bind-null.js @@ -8,7 +8,7 @@ let rows; connection.execute( 'SELECT ? AS firstValue, ? AS nullValue, ? AS lastValue', ['foo', null, 'bar'], - function(err, _rows) { + (err, _rows) => { if (err) { throw err; } @@ -17,7 +17,7 @@ connection.execute( } ); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [ { firstValue: 'foo', nullValue: null, lastValue: 'bar' } ]); diff --git a/test/integration/connection/test-execute-bind-number.js b/test/integration/connection/test-execute-bind-number.js index 5b7ab676ac..d29dc1328e 100644 --- a/test/integration/connection/test-execute-bind-number.js +++ b/test/integration/connection/test-execute-bind-number.js @@ -8,7 +8,7 @@ let rows; connection.execute( 'SELECT ? AS zeroValue, ? AS positiveValue, ? AS negativeValue, ? AS decimalValue', [0, 123, -123, 1.25], - function(err, _rows) { + (err, _rows) => { if (err) { throw err; } @@ -17,7 +17,7 @@ connection.execute( } ); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [ { zeroValue: 0, diff --git a/test/integration/connection/test-execute-bind-undefined.js b/test/integration/connection/test-execute-bind-undefined.js index f12f193750..0163b4722e 100644 --- a/test/integration/connection/test-execute-bind-undefined.js +++ b/test/integration/connection/test-execute-bind-undefined.js @@ -7,13 +7,13 @@ const assert = require('assert'); let error = null; try { - connection.execute('SELECT ? AS result', [undefined], function() {}); + connection.execute('SELECT ? AS result', [undefined], () => {}); } catch (err) { error = err; connection.end(); } -process.on('exit', function() { +process.on('exit', () => { assert.equal(error.name, 'TypeError'); if (!error.message.match(/undefined/)) { assert.fail("Expected error.message to contain 'undefined'"); diff --git a/test/integration/connection/test-execute-cached.js b/test/integration/connection/test-execute-cached.js index 9140f3432d..2310b483e6 100644 --- a/test/integration/connection/test-execute-cached.js +++ b/test/integration/connection/test-execute-cached.js @@ -11,17 +11,17 @@ let rows2 = undefined; const q = 'select 1 + ? as test'; const key = 'undefined/undefined/undefined' + q; -connection.execute(q, [123], function(err, _rows) { +connection.execute(q, [123], (err, _rows) => { if (err) { throw err; } rows = _rows; - connection.execute(q, [124], function(err, _rows) { + connection.execute(q, [124], (err, _rows) => { if (err) { throw err; } rows1 = _rows; - connection.execute(q, [125], function(err, _rows) { + connection.execute(q, [125], (err, _rows) => { if (err) { throw err; } @@ -34,7 +34,7 @@ connection.execute(q, [123], function(err, _rows) { }); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ test: 124 }]); assert.deepEqual(rows1, [{ test: 125 }]); assert.deepEqual(rows2, [{ test: 126 }]); diff --git a/test/integration/connection/test-execute-newdecimal.js b/test/integration/connection/test-execute-newdecimal.js index feb283b1f7..9ada5d042d 100644 --- a/test/integration/connection/test-execute-newdecimal.js +++ b/test/integration/connection/test-execute-newdecimal.js @@ -8,7 +8,7 @@ connection.query('CREATE TEMPORARY TABLE t (f DECIMAL(19,4))'); connection.query('INSERT INTO t VALUES(12345.67)'); let rows, fields; -connection.execute('SELECT f FROM t', function(err, _rows, _fields) { +connection.execute('SELECT f FROM t', (err, _rows, _fields) => { if (err) { throw err; } @@ -17,7 +17,7 @@ connection.execute('SELECT f FROM t', function(err, _rows, _fields) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ f: '12345.6700' }]); assert.equal(fields[0].name, 'f'); }); diff --git a/test/integration/connection/test-execute-nocolumndef.js b/test/integration/connection/test-execute-nocolumndef.js index a578f64c3b..9987fd38b8 100644 --- a/test/integration/connection/test-execute-nocolumndef.js +++ b/test/integration/connection/test-execute-nocolumndef.js @@ -11,7 +11,7 @@ const assert = require('assert-diff'); let rows; let fields; -connection.execute('explain SELECT 1', function(err, _rows, _fields) { +connection.execute('explain SELECT 1', (err, _rows, _fields) => { if (err) { throw err; } @@ -197,7 +197,7 @@ const expectedFields = [ } ]; -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, expectedRows); fields.forEach((f, index) => { const fi = f.inspect(); diff --git a/test/integration/connection/test-execute-null-bitmap.js b/test/integration/connection/test-execute-null-bitmap.js index 19867be745..f7db53a29b 100644 --- a/test/integration/connection/test-execute-null-bitmap.js +++ b/test/integration/connection/test-execute-null-bitmap.js @@ -8,15 +8,10 @@ const params = [1, 2]; let query = 'select ? + ?'; function dotest() { - connection.execute(query + ' as t', params, function(err, _rows) { + connection.execute(query + ' as t', params, (err, _rows) => { assert.equal(err, null); if (params.length < 50) { - assert.equal( - _rows[0].t, - params.reduce(function(x, y) { - return x + y; - }) - ); + assert.equal(_rows[0].t, params.reduce((x, y) => x + y)); query += ' + ?'; params.push(params.length); dotest(); diff --git a/test/integration/connection/test-execute-order.js b/test/integration/connection/test-execute-order.js index f2d612683f..2e187be4c2 100644 --- a/test/integration/connection/test-execute-order.js +++ b/test/integration/connection/test-execute-order.js @@ -5,20 +5,20 @@ const connection = common.createConnection(); const assert = require('assert'); const order = []; -connection.execute('select 1+2', function(err) { +connection.execute('select 1+2', err => { assert.ifError(err); order.push(0); }); -connection.execute('select 2+2', function(err) { +connection.execute('select 2+2', err => { assert.ifError(err); order.push(1); }); -connection.query('select 1+1', function(err) { +connection.query('select 1+1', err => { assert.ifError(err); order.push(2); connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(order, [0, 1, 2]); }); diff --git a/test/integration/connection/test-execute-signed.js b/test/integration/connection/test-execute-signed.js index 9372aa6e5c..909a3887e7 100644 --- a/test/integration/connection/test-execute-signed.js +++ b/test/integration/connection/test-execute-signed.js @@ -24,7 +24,7 @@ connection.query('insert into test_table(num,l) values(4+?, 4000000-?)', [ 8000000 ]); -connection.execute('SELECT * from test_table', [], function(err, _rows) { +connection.execute('SELECT * from test_table', [], (err, _rows) => { if (err) { throw err; } @@ -32,7 +32,7 @@ connection.execute('SELECT * from test_table', [], function(err, _rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [ { id: 1, num: 1, l: 3 }, { id: 2, num: -2, l: -10 }, diff --git a/test/integration/connection/test-execute-type-casting.js b/test/integration/connection/test-execute-type-casting.js index ab3ff5cd05..ad7eb7b3f9 100644 --- a/test/integration/connection/test-execute-type-casting.js +++ b/test/integration/connection/test-execute-type-casting.js @@ -13,7 +13,7 @@ const table = 'type_casting'; const schema = []; const inserts = []; -tests.forEach(function(test, index) { +tests.forEach((test, index) => { const escaped = test.insertRaw || connection.escape(test.insert); test.columnName = test.type + '_' + index; @@ -35,20 +35,21 @@ connection.query(createTable); connection.query('INSERT INTO ' + table + ' SET' + inserts.join(',\n')); let row; -connection.execute('SELECT * FROM ' + table + ' WHERE id = ?;', [1], function( - err, - rows -) { - if (err) { - throw err; - } +connection.execute( + 'SELECT * FROM ' + table + ' WHERE id = ?;', + [1], + (err, rows) => { + if (err) { + throw err; + } - row = rows[0]; - connection.end(); -}); + row = rows[0]; + connection.end(); + } +); -process.on('exit', function() { - tests.forEach(function(test) { +process.on('exit', () => { + tests.forEach(test => { let expected = test.expect || test.insert; let got = row[test.columnName]; let message; diff --git a/test/integration/connection/test-insert-bigint-big-number-strings.js b/test/integration/connection/test-insert-bigint-big-number-strings.js index 5a1f529fac..9e4f51eb0b 100644 --- a/test/integration/connection/test-insert-bigint-big-number-strings.js +++ b/test/integration/connection/test-insert-bigint-big-number-strings.js @@ -18,31 +18,25 @@ connection.query( ); connection.query("INSERT INTO bigs SET title='test', id=123"); -connection.query("INSERT INTO bigs SET title='test1'", function(err, result) { +connection.query("INSERT INTO bigs SET title='test1'", (err, result) => { if (err) { throw err; } assert.strictEqual(result.insertId, 124); // > 24 bits connection.query("INSERT INTO bigs SET title='test', id=123456789"); - connection.query("INSERT INTO bigs SET title='test2'", function(err, result) { + connection.query("INSERT INTO bigs SET title='test2'", (err, result) => { assert.strictEqual(result.insertId, 123456790); // big int connection.query("INSERT INTO bigs SET title='test', id=9007199254740992"); - connection.query("INSERT INTO bigs SET title='test3'", function( - err, - result - ) { + connection.query("INSERT INTO bigs SET title='test3'", (err, result) => { assert.strictEqual(result.insertId, '9007199254740993'); connection.query( "INSERT INTO bigs SET title='test', id=90071992547409924" ); - connection.query("INSERT INTO bigs SET title='test4'", function( - err, - result - ) { + connection.query("INSERT INTO bigs SET title='test4'", (err, result) => { assert.strictEqual(result.insertId, '90071992547409925'); - connection.query('select * from bigs', function(err, result) { + connection.query('select * from bigs', (err, result) => { assert.strictEqual(result[0].id, '123'); assert.strictEqual(result[1].id, '124'); assert.strictEqual(result[2].id, '123456789'); diff --git a/test/integration/connection/test-insert-bigint.js b/test/integration/connection/test-insert-bigint.js index fc693644a3..b4e8f68a69 100644 --- a/test/integration/connection/test-insert-bigint.js +++ b/test/integration/connection/test-insert-bigint.js @@ -16,21 +16,18 @@ connection.query( ); connection.query("INSERT INTO bigs SET title='test', id=123"); -connection.query("INSERT INTO bigs SET title='test1'", function(err, result) { +connection.query("INSERT INTO bigs SET title='test1'", (err, result) => { if (err) { throw err; } assert.strictEqual(result.insertId, 124); // > 24 bits connection.query("INSERT INTO bigs SET title='test', id=123456789"); - connection.query("INSERT INTO bigs SET title='test2'", function(err, result) { + connection.query("INSERT INTO bigs SET title='test2'", (err, result) => { assert.strictEqual(result.insertId, 123456790); // big int connection.query("INSERT INTO bigs SET title='test', id=9007199254740992"); - connection.query("INSERT INTO bigs SET title='test3'", function( - err, - result - ) { + connection.query("INSERT INTO bigs SET title='test3'", (err, result) => { assert.strictEqual( Long.fromString('9007199254740993').compare(result.insertId), 0 @@ -38,10 +35,7 @@ connection.query("INSERT INTO bigs SET title='test1'", function(err, result) { connection.query( "INSERT INTO bigs SET title='test', id=90071992547409924" ); - connection.query("INSERT INTO bigs SET title='test4'", function( - err, - result - ) { + connection.query("INSERT INTO bigs SET title='test4'", (err, result) => { assert.strictEqual( Long.fromString('90071992547409925').compare(result.insertId), 0 @@ -52,7 +46,7 @@ connection.query("INSERT INTO bigs SET title='test1'", function(err, result) { supportBigNumbers: true, bigNumberString: false }, - function(err, result) { + (err, result) => { assert.strictEqual(result[0].id, 123); assert.strictEqual(result[1].id, 124); assert.strictEqual(result[2].id, 123456789); diff --git a/test/integration/connection/test-insert-large-blob.js b/test/integration/connection/test-insert-large-blob.js index 8c009bdfe5..e2832a0249 100644 --- a/test/integration/connection/test-insert-large-blob.js +++ b/test/integration/connection/test-insert-large-blob.js @@ -37,7 +37,7 @@ if (false) { connection.query( 'SET GLOBAL max_allowed_packet=' + (length * 2 + 2000), - function(err) { + err => { assert.ifError(err); connection.end(); const connection2 = common.createConnection(); @@ -53,17 +53,17 @@ if (false) { connection2.query( 'INSERT INTO ' + table + ' (content) VALUES(?)', [content], - function(err, _result) { + (err, _result) => { assert.ifError(err); result = _result; connection2.query( 'SELECT * FROM ' + table + ' WHERE id = ' + result.insertId, - function(err, _result2) { + (err, _result2) => { result2 = _result2; connection2.query( 'INSERT INTO ' + table + ' (content) VALUES(?)', [content1], - function(err, _result) { + (err, _result) => { assert.ifError(err); result3 = _result; connection2.query( @@ -71,7 +71,7 @@ if (false) { table + ' WHERE id = ' + result3.insertId, - function(err, _result) { + (err, _result) => { assert.ifError(err); result4 = _result; connection2.end(); @@ -86,7 +86,7 @@ if (false) { } ); - process.on('exit', function() { + process.on('exit', () => { assert.equal(result2[0].id, String(result.insertId)); assert.equal(result2[0].content.toString('hex'), content.toString('hex')); assert.equal(result4[0].content.toString('hex'), content1.toString('hex')); diff --git a/test/integration/connection/test-insert-negative-ai.js b/test/integration/connection/test-insert-negative-ai.js index 65f613eb2e..9caf236453 100644 --- a/test/integration/connection/test-insert-negative-ai.js +++ b/test/integration/connection/test-insert-negative-ai.js @@ -19,14 +19,14 @@ const testNegativeAI = function(err) { ' (id, title) values (-999, "' + testData + '")', - function(err, result) { + (err, result) => { assert.ifError(err); insertResult = result; // select the row with negative AI connection.query( 'SELECT * FROM `' + testTable + '`' + ' WHERE id = ' + result.insertId, - function(err, result_) { + (err, result_) => { assert.ifError(err); selectResult = result_; connection.end(); @@ -51,7 +51,7 @@ const prepareAndTest = function() { prepareAndTest(); -process.on('exit', function() { +process.on('exit', () => { assert.strictEqual(insertResult.insertId, -999); assert.strictEqual(selectResult.length, 1); diff --git a/test/integration/connection/test-insert-results.js b/test/integration/connection/test-insert-results.js index b6fc832fd8..0d740ef54d 100644 --- a/test/integration/connection/test-insert-results.js +++ b/test/integration/connection/test-insert-results.js @@ -20,24 +20,24 @@ connection.query( ); let result, result2; -connection.query('INSERT INTO ' + table + ' SET title="' + text + '"', function( - err, - _result -) { - if (err) { - throw err; - } - result = _result; - connection.query( - 'SELECT * FROM ' + table + ' WHERE id = ' + result.insertId, - function(err, _result2) { - result2 = _result2; - connection.end(); +connection.query( + 'INSERT INTO ' + table + ' SET title="' + text + '"', + (err, _result) => { + if (err) { + throw err; } - ); -}); + result = _result; + connection.query( + 'SELECT * FROM ' + table + ' WHERE id = ' + result.insertId, + (err, _result2) => { + result2 = _result2; + connection.end(); + } + ); + } +); -process.on('exit', function() { +process.on('exit', () => { assert.strictEqual(result.insertId, 1); assert.strictEqual(result2.length, 1); // TODO: type conversions diff --git a/test/integration/connection/test-invalid-date-result.js b/test/integration/connection/test-invalid-date-result.js index 2866790172..322fff3a5b 100644 --- a/test/integration/connection/test-invalid-date-result.js +++ b/test/integration/connection/test-invalid-date-result.js @@ -6,7 +6,7 @@ const assert = require('assert'); let rows = undefined; -connection.execute('SELECT TIMESTAMP(0000-00-00) t', [], function(err, _rows) { +connection.execute('SELECT TIMESTAMP(0000-00-00) t', [], (err, _rows) => { if (err) { throw err; } @@ -18,7 +18,7 @@ function isInvalidTime(t) { return isNaN(t.getTime()); } -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(Object.prototype.toString.call(rows[0].t), '[object Date]'); assert.deepEqual(isInvalidTime(rows[0].t), true); }); diff --git a/test/integration/connection/test-load-infile.js b/test/integration/connection/test-load-infile.js index ac2107720c..41876a08ee 100644 --- a/test/integration/connection/test-load-infile.js +++ b/test/integration/connection/test-load-infile.js @@ -23,7 +23,7 @@ const sql = 'FIELDS TERMINATED BY ? (id, title)'; let ok; -connection.query(sql, [path, ','], function(err, _ok) { +connection.query(sql, [path, ','], (err, _ok) => { if (err) { throw err; } @@ -31,7 +31,7 @@ connection.query(sql, [path, ','], function(err, _ok) { }); let rows; -connection.query('SELECT * FROM ' + table, function(err, _rows) { +connection.query('SELECT * FROM ' + table, (err, _rows) => { if (err) { throw err; } @@ -43,7 +43,7 @@ let loadErr; let loadResult; const badPath = '/does_not_exist.csv'; -connection.query(sql, [badPath, ','], function(err, result) { +connection.query(sql, [badPath, ','], (err, result) => { loadErr = err; loadResult = result; }); @@ -52,7 +52,7 @@ connection.query(sql, [badPath, ','], function(err, result) { const createMyStream = function() { const Stream = require('stream').PassThrough; const myStream = new Stream(); - setTimeout(function() { + setTimeout(() => { myStream.write('11,Hello World\n'); myStream.write('21,One '); myStream.write('more row\n'); @@ -68,7 +68,7 @@ connection.query( values: [badPath, ','], infileStreamFactory: createMyStream }, - function(err, result) { + (err, result) => { if (err) { throw err; } @@ -77,7 +77,7 @@ connection.query( } ); -process.on('exit', function() { +process.on('exit', () => { assert.equal(ok.affectedRows, 4); assert.equal(rows.length, 4); assert.equal(rows[0].id, 1); diff --git a/test/integration/connection/test-multiple-results.js b/test/integration/connection/test-multiple-results.js index 77ffa1bbfc..2f47859aa7 100644 --- a/test/integration/connection/test-multiple-results.js +++ b/test/integration/connection/test-multiple-results.js @@ -101,7 +101,7 @@ function do_test(testIndex) { const entry = tests[testIndex]; const sql = entry[0]; const expectation = entry[1]; - mysql.query(sql, function(err, _rows, _columns) { + mysql.query(sql, (err, _rows, _columns) => { let _numResults = 0; if (_rows.constructor.name == 'ResultSetHeader') { _numResults = 1; @@ -185,7 +185,7 @@ function do_test(testIndex) { } q.on('result', checkRow); q.on('fields', checkFields); - q.on('end', function() { + q.on('end', () => { if (testIndex + 1 < tests.length) { do_test(testIndex + 1); } else { diff --git a/test/integration/connection/test-named-paceholders.js b/test/integration/connection/test-named-paceholders.js index 598170f923..5c2483bca1 100644 --- a/test/integration/connection/test-named-paceholders.js +++ b/test/integration/connection/test-named-paceholders.js @@ -30,7 +30,7 @@ connection.config.namedPlaceholders = true; const cmd = connection.execute( 'SELECT * from test_table where num1 < :numParam and num2 > :lParam', { lParam: 100, numParam: 2 }, - function(err, rows) { + (err, rows) => { if (err) { throw err; } @@ -40,7 +40,7 @@ const cmd = connection.execute( assert.equal(cmd.sql, 'SELECT * from test_table where num1 < ? and num2 > ?'); assert.deepEqual(cmd.values, [2, 100]); -connection.execute('SELECT :a + :a as sum', { a: 2 }, function(err, rows) { +connection.execute('SELECT :a + :a as sum', { a: 2 }, (err, rows) => { if (err) { throw err; } @@ -50,7 +50,7 @@ connection.execute('SELECT :a + :a as sum', { a: 2 }, function(err, rows) { const qCmd = connection.query( 'SELECT * from test_table where num1 < :numParam and num2 > :lParam', { lParam: 100, numParam: 2 }, - function(err, rows) { + (err, rows) => { if (err) { throw err; } @@ -63,7 +63,7 @@ assert.equal( ); assert.deepEqual(qCmd.values, [2, 100]); -connection.query('SELECT :a + :a as sum', { a: 2 }, function(err, rows) { +connection.query('SELECT :a + :a as sum', { a: 2 }, (err, rows) => { if (err) { throw err; } @@ -79,7 +79,7 @@ assert.equal(sql, 'SELECT * from test_table where num1 < 2 and num2 > 100'); const pool = common.createPool(); pool.config.connectionConfig.namedPlaceholders = true; -pool.query('SELECT :a + :a as sum', { a: 2 }, function(err, rows) { +pool.query('SELECT :a + :a as sum', { a: 2 }, (err, rows) => { pool.end(); if (err) { throw err; diff --git a/test/integration/connection/test-nested-tables-query.js b/test/integration/connection/test-nested-tables-query.js index 0ed192a686..f49d5ecf3e 100644 --- a/test/integration/connection/test-nested-tables-query.js +++ b/test/integration/connection/test-nested-tables-query.js @@ -33,7 +33,7 @@ const options3 = { }; let rows1, rows2, rows3, rows1e, rows2e, rows3e; -connection.query(options1, function(err, _rows) { +connection.query(options1, (err, _rows) => { if (err) { throw err; } @@ -41,7 +41,7 @@ connection.query(options1, function(err, _rows) { rows1 = _rows; }); -connection.query(options2, function(err, _rows) { +connection.query(options2, (err, _rows) => { if (err) { throw err; } @@ -49,7 +49,7 @@ connection.query(options2, function(err, _rows) { rows2 = _rows; }); -connection.query(options3, function(err, _rows) { +connection.query(options3, (err, _rows) => { if (err) { throw err; } @@ -57,7 +57,7 @@ connection.query(options3, function(err, _rows) { rows3 = _rows; }); -connection.execute(options1, function(err, _rows) { +connection.execute(options1, (err, _rows) => { if (err) { throw err; } @@ -65,7 +65,7 @@ connection.execute(options1, function(err, _rows) { rows1e = _rows; }); -connection.execute(options2, function(err, _rows) { +connection.execute(options2, (err, _rows) => { if (err) { throw err; } @@ -73,7 +73,7 @@ connection.execute(options2, function(err, _rows) { rows2e = _rows; }); -connection.execute(options3, function(err, _rows) { +connection.execute(options3, (err, _rows) => { if (err) { throw err; } @@ -82,7 +82,7 @@ connection.execute(options3, function(err, _rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(rows1.length, 1); assert.equal(rows1[0].nested_test.id, 1); assert.equal(rows1[0].nested_test.title, 'test'); diff --git a/test/integration/connection/test-null-buffer.js b/test/integration/connection/test-null-buffer.js index 7133e99487..df3a155ed4 100644 --- a/test/integration/connection/test-null-buffer.js +++ b/test/integration/connection/test-null-buffer.js @@ -10,12 +10,12 @@ let rowsBinaryProtocol; connection.query('CREATE TEMPORARY TABLE binary_table (stuff BINARY(16));'); connection.query('INSERT INTO binary_table VALUES(null)'); -connection.query('SELECT * from binary_table', function(err, _rows) { +connection.query('SELECT * from binary_table', (err, _rows) => { if (err) { throw err; } rowsTextProtocol = _rows; - connection.execute('SELECT * from binary_table', function(err, _rows) { + connection.execute('SELECT * from binary_table', (err, _rows) => { if (err) { throw err; } @@ -24,7 +24,7 @@ connection.query('SELECT * from binary_table', function(err, _rows) { }); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rowsTextProtocol[0], { stuff: null }); assert.deepEqual(rowsBinaryProtocol[0], { stuff: null }); }); diff --git a/test/integration/connection/test-null-double.js b/test/integration/connection/test-null-double.js index d3aa4f22e8..6937311a43 100644 --- a/test/integration/connection/test-null-double.js +++ b/test/integration/connection/test-null-double.js @@ -10,7 +10,7 @@ connection.query('CREATE TEMPORARY TABLE t (i int)'); connection.query('INSERT INTO t VALUES(null)'); connection.query('INSERT INTO t VALUES(123)'); -connection.query('SELECT * from t', function(err, _rows) { +connection.query('SELECT * from t', (err, _rows) => { if (err) { throw err; } @@ -18,7 +18,7 @@ connection.query('SELECT * from t', function(err, _rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows[0], { i: null }); assert.deepEqual(rows[1], { i: 123 }); }); diff --git a/test/integration/connection/test-null-int.js b/test/integration/connection/test-null-int.js index d3aa4f22e8..6937311a43 100644 --- a/test/integration/connection/test-null-int.js +++ b/test/integration/connection/test-null-int.js @@ -10,7 +10,7 @@ connection.query('CREATE TEMPORARY TABLE t (i int)'); connection.query('INSERT INTO t VALUES(null)'); connection.query('INSERT INTO t VALUES(123)'); -connection.query('SELECT * from t', function(err, _rows) { +connection.query('SELECT * from t', (err, _rows) => { if (err) { throw err; } @@ -18,7 +18,7 @@ connection.query('SELECT * from t', function(err, _rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows[0], { i: null }); assert.deepEqual(rows[1], { i: 123 }); }); diff --git a/test/integration/connection/test-null.js b/test/integration/connection/test-null.js index f650e21965..0317866115 100644 --- a/test/integration/connection/test-null.js +++ b/test/integration/connection/test-null.js @@ -9,14 +9,14 @@ let fields, fields1; connection.query('CREATE TEMPORARY TABLE t (i int)'); connection.query('INSERT INTO t VALUES(null)'); -connection.query('SELECT cast(NULL AS CHAR)', function(err, _rows, _fields) { +connection.query('SELECT cast(NULL AS CHAR)', (err, _rows, _fields) => { if (err) { throw err; } rows = _rows; fields = _fields; }); -connection.query('SELECT * from t', function(err, _rows, _fields) { +connection.query('SELECT * from t', (err, _rows, _fields) => { if (err) { throw err; } @@ -25,7 +25,7 @@ connection.query('SELECT * from t', function(err, _rows, _fields) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ 'cast(NULL AS CHAR)': null }]); assert.equal(fields[0].columnType, 253); assert.deepEqual(rows1, [{ i: null }]); diff --git a/test/integration/connection/test-parameters-questionmark.js b/test/integration/connection/test-parameters-questionmark.js index 0c2cffec96..e2efe4bc9f 100644 --- a/test/integration/connection/test-parameters-questionmark.js +++ b/test/integration/connection/test-parameters-questionmark.js @@ -20,7 +20,7 @@ pool.query('UPDATE test_table SET str = ? WHERE id = ?', [ 'should not change ?', 1 ]); -pool.query('SELECT str FROM test_table WHERE id = ?', [1], function(err, rows) { +pool.query('SELECT str FROM test_table WHERE id = ?', [1], (err, rows) => { pool.end(); if (err) { throw err; diff --git a/test/integration/connection/test-prepare-and-close.js b/test/integration/connection/test-prepare-and-close.js index c0146635af..b0700097c4 100644 --- a/test/integration/connection/test-prepare-and-close.js +++ b/test/integration/connection/test-prepare-and-close.js @@ -7,7 +7,7 @@ const assert = require('assert'); const max = 500; const start = process.hrtime(); function prepare(i) { - connection.prepare('select 1+' + i, function(err, stmt) { + connection.prepare('select 1+' + i, (err, stmt) => { assert.ifError(err); stmt.close(); if (!err) { @@ -18,7 +18,7 @@ function prepare(i) { connection.end(); return; } - setTimeout(function() { + setTimeout(() => { prepare(i + 1); }, 2); return; @@ -26,7 +26,7 @@ function prepare(i) { assert(0, 'Error in prepare!'); }); } -connection.query('SET GLOBAL max_prepared_stmt_count=10', function(err) { +connection.query('SET GLOBAL max_prepared_stmt_count=10', err => { assert.ifError(err); prepare(1); }); diff --git a/test/integration/connection/test-prepare-simple.js b/test/integration/connection/test-prepare-simple.js index be84a1a4df..70199a61fc 100644 --- a/test/integration/connection/test-prepare-simple.js +++ b/test/integration/connection/test-prepare-simple.js @@ -9,14 +9,14 @@ const query1 = 'select 1 + ? + ? as test'; const query2 = 'select 1 + 1'; // no parameters const query3 = 'create temporary table aaa(i int);'; // no parameters, no result columns -connection.prepare(query1, function(err1, stmt1) { +connection.prepare(query1, (err1, stmt1) => { assert.ifError(err1); _stmt1 = stmt1; _stmt1.close(); - connection.prepare(query2, function(err2, stmt2) { + connection.prepare(query2, (err2, stmt2) => { assert.ifError(err2); _stmt2 = stmt2; - connection.prepare(query3, function(err3, stmt3) { + connection.prepare(query3, (err3, stmt3) => { assert.ifError(err3); _stmt3 = stmt3; _stmt2.close(); @@ -26,7 +26,7 @@ connection.prepare(query1, function(err1, stmt1) { }); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(_stmt1.query, query1); assert(_stmt1.id >= 0); assert.equal(_stmt1.columns.length, 1); diff --git a/test/integration/connection/test-prepare-then-execute.js b/test/integration/connection/test-prepare-then-execute.js index 9d8ac7680c..4f50ba00b1 100644 --- a/test/integration/connection/test-prepare-then-execute.js +++ b/test/integration/connection/test-prepare-then-execute.js @@ -8,12 +8,12 @@ let _stmt = null; let _columns = null; let _rows = null; -connection.prepare('select 1 + ? + ? as test', function(err, stmt) { +connection.prepare('select 1 + ? + ? as test', (err, stmt) => { if (err) { throw err; } _stmt = stmt; - stmt.execute([111, 123], function(err, rows, columns) { + stmt.execute([111, 123], (err, rows, columns) => { if (err) { throw err; } @@ -23,7 +23,7 @@ connection.prepare('select 1 + ? + ? as test', function(err, stmt) { }); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(_stmt.columns.length, 1); assert.equal(_stmt.parameters.length, 2); assert.deepEqual(_rows, [{ test: 235 }]); diff --git a/test/integration/connection/test-protocol-errors.js b/test/integration/connection/test-protocol-errors.js index 00c3a1c2e5..23b5b3ed04 100644 --- a/test/integration/connection/test-protocol-errors.js +++ b/test/integration/connection/test-protocol-errors.js @@ -10,7 +10,7 @@ let rows; const server = common.createServer( () => { const connection = common.createConnection({ port: server._port }); - connection.query(query, function(err, _rows, _fields) { + connection.query(query, (err, _rows, _fields) => { if (err) { throw err; } @@ -18,7 +18,7 @@ const server = common.createServer( fields = _fields; }); - connection.on('error', function(err) { + connection.on('error', err => { error = err; if (server._server._handle) { server.close(); @@ -26,7 +26,7 @@ const server = common.createServer( }); }, conn => { - conn.on('query', function() { + conn.on('query', () => { conn.writeTextResult( [{ '1': '1' }], [ @@ -51,7 +51,7 @@ const server = common.createServer( } ); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ 1: 1 }]); assert.equal(fields[0].name, '1'); assert.equal( diff --git a/test/integration/connection/test-quit.js b/test/integration/connection/test-quit.js index 587d64bd21..44d1c9baa3 100644 --- a/test/integration/connection/test-quit.js +++ b/test/integration/connection/test-quit.js @@ -11,7 +11,7 @@ const server = common.createServer( () => { const connection = common.createConnection({ port: server._port }); - connection.query(queryCli, function(err, _rows, _fields) { + connection.query(queryCli, (err, _rows, _fields) => { if (err) { throw err; } @@ -22,14 +22,14 @@ const server = common.createServer( }); }, conn => { - conn.on('quit', function() { + conn.on('quit', () => { // COM_QUIT quitReceived = true; conn.stream.end(); server.close(); }); - conn.on('query', function(q) { + conn.on('query', q => { queryServ = q; conn.writeTextResult( [{ '1': '1' }], @@ -53,7 +53,7 @@ const server = common.createServer( } ); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ 1: 1 }]); assert.equal(fields[0].name, '1'); assert.equal(quitReceived, true); diff --git a/test/integration/connection/test-select-1.js b/test/integration/connection/test-select-1.js index 7f367812aa..267dd7d654 100644 --- a/test/integration/connection/test-select-1.js +++ b/test/integration/connection/test-select-1.js @@ -6,7 +6,7 @@ const assert = require('assert'); let rows = undefined; let fields = undefined; -connection.query('SELECT 1', function(err, _rows, _fields) { +connection.query('SELECT 1', (err, _rows, _fields) => { if (err) { throw err; } @@ -16,7 +16,7 @@ connection.query('SELECT 1', function(err, _rows, _fields) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ 1: 1 }]); assert.equal(fields[0].name, '1'); }); diff --git a/test/integration/connection/test-select-empty-string.js b/test/integration/connection/test-select-empty-string.js index 732596b477..dfff0166a8 100644 --- a/test/integration/connection/test-select-empty-string.js +++ b/test/integration/connection/test-select-empty-string.js @@ -5,7 +5,7 @@ const connection = common.createConnection(); const assert = require('assert'); let rows; -connection.query('SELECT ""', function(err, _rows) { +connection.query('SELECT ""', (err, _rows) => { if (err) { throw err; } @@ -14,6 +14,6 @@ connection.query('SELECT ""', function(err, _rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ '': '' }]); }); diff --git a/test/integration/connection/test-select-json.js b/test/integration/connection/test-select-json.js index b2cd56e300..142f38bcd3 100644 --- a/test/integration/connection/test-select-json.js +++ b/test/integration/connection/test-select-json.js @@ -15,12 +15,12 @@ const face = '\uD83D\uDE02'; connection.query('CREATE TEMPORARY TABLE json_test (json_test JSON)'); connection.query('INSERT INTO json_test VALUES (?)', JSON.stringify(face)); -connection.query('SELECT * FROM json_test', function(err, _rows) { +connection.query('SELECT * FROM json_test', (err, _rows) => { if (err) { throw err; } textFetchedRows = _rows; - connection.execute('SELECT * FROM json_test', function(err, _rows) { + connection.execute('SELECT * FROM json_test', (err, _rows) => { if (err) { throw err; } @@ -29,7 +29,7 @@ connection.query('SELECT * FROM json_test', function(err, _rows) { }); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(textFetchedRows[0].json_test, face); assert.equal(binaryFetchedRows[0].json_test, face); }); diff --git a/test/integration/connection/test-select-negative.js b/test/integration/connection/test-select-negative.js index 5090754e64..a90d938474 100644 --- a/test/integration/connection/test-select-negative.js +++ b/test/integration/connection/test-select-negative.js @@ -7,14 +7,14 @@ const assert = require('assert'); let rows = undefined; let rows1 = undefined; -connection.execute('SELECT -1 v', [], function(err, _rows) { +connection.execute('SELECT -1 v', [], (err, _rows) => { if (err) { throw err; } rows = _rows; }); -connection.query('SELECT -1 v', function(err, _rows) { +connection.query('SELECT -1 v', (err, _rows) => { if (err) { throw err; } @@ -22,7 +22,7 @@ connection.query('SELECT -1 v', function(err, _rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [{ v: -1 }]); assert.deepEqual(rows1, [{ v: -1 }]); }); diff --git a/test/integration/connection/test-select-utf8.js b/test/integration/connection/test-select-utf8.js index 0af425983d..e685a3756d 100644 --- a/test/integration/connection/test-select-utf8.js +++ b/test/integration/connection/test-select-utf8.js @@ -7,11 +7,7 @@ const assert = require('assert'); let rows = undefined; let fields = undefined; const multibyteText = '本日は晴天なり'; -connection.query("SELECT '" + multibyteText + "'", function( - err, - _rows, - _fields -) { +connection.query("SELECT '" + multibyteText + "'", (err, _rows, _fields) => { if (err) { throw err; } @@ -20,7 +16,7 @@ connection.query("SELECT '" + multibyteText + "'", function( connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(rows[0][multibyteText], multibyteText); assert.equal(fields[0].name, multibyteText); }); diff --git a/test/integration/connection/test-server-listen.js b/test/integration/connection/test-server-listen.js index 4a3ad6e423..967a40e739 100644 --- a/test/integration/connection/test-server-listen.js +++ b/test/integration/connection/test-server-listen.js @@ -10,10 +10,10 @@ function testListen(argsDescription, listenCaller) { const server = mysql.createServer(); let listenCallbackFired = false; - listenCaller(server, function() { + listenCaller(server, () => { listenCallbackFired = true; }); - setTimeout(function() { + setTimeout(() => { assert.ok( listenCallbackFired, 'Callback for call with ' + argsDescription + ' did not fire' @@ -22,14 +22,14 @@ function testListen(argsDescription, listenCaller) { }, 100); } -testListen('port', function(server, callback) { +testListen('port', (server, callback) => { server.listen(0, callback); }); -testListen('port, host', function(server, callback) { +testListen('port, host', (server, callback) => { server.listen(0, '127.0.0.1', callback); }); -testListen('port, host, backlog', function(server, callback) { +testListen('port, host, backlog', (server, callback) => { server.listen(0, '127.0.0.1', 50, callback); }); diff --git a/test/integration/connection/test-signed-tinyint.js b/test/integration/connection/test-signed-tinyint.js index 894cbb8056..3a365b0456 100644 --- a/test/integration/connection/test-signed-tinyint.js +++ b/test/integration/connection/test-signed-tinyint.js @@ -12,7 +12,7 @@ connection.query( connection.query('INSERT INTO signed_ints values (-3, -120, 500)'); connection.query('INSERT INTO signed_ints values (3, -110, -500)'); -connection.execute('SELECT * from signed_ints', [5], function(err, _rows) { +connection.execute('SELECT * from signed_ints', [5], (err, _rows) => { if (err) { throw err; } @@ -20,7 +20,7 @@ connection.execute('SELECT * from signed_ints', [5], function(err, _rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows, [ { b11: -3, b12: -120, b21: 500 }, { b11: 3, b12: -110, b21: -500 } diff --git a/test/integration/connection/test-stream-errors.js b/test/integration/connection/test-stream-errors.js index 10104eac25..bf821fc883 100644 --- a/test/integration/connection/test-stream-errors.js +++ b/test/integration/connection/test-stream-errors.js @@ -13,21 +13,21 @@ const query = 'SELECT 1'; const server = common.createServer( () => { clientConnection = common.createConnection({ port: server._port }); - clientConnection.query(query, function(err) { + clientConnection.query(query, err => { receivedError1 = err; }); - clientConnection.query('second query, should not be executed', function() { + clientConnection.query('second query, should not be executed', () => { receivedError2 = err; clientConnection.query( 'trying to enqueue command to a connection which is already in error state', - function(err1) { + err1 => { receivedError3 = err1; } ); }); }, conn => { - conn.on('query', function() { + conn.on('query', () => { conn.writeColumns([ { catalog: 'def', @@ -51,7 +51,7 @@ const server = common.createServer( } ); -process.on('exit', function() { +process.on('exit', () => { assert.equal(receivedError1.fatal, true); assert.equal(receivedError1.code, err.code); assert.equal(receivedError2.fatal, true); diff --git a/test/integration/connection/test-stream.js b/test/integration/connection/test-stream.js index 049ec8fb83..133acc8426 100644 --- a/test/integration/connection/test-stream.js +++ b/test/integration/connection/test-stream.js @@ -17,7 +17,7 @@ connection.query( 'PRIMARY KEY (`id`)', ') ENGINE=InnoDB DEFAULT CHARSET=utf8' ].join('\n'), - function(err) { + err => { if (err) { throw err; } @@ -27,7 +27,7 @@ connection.query( connection.execute( 'INSERT INTO announcements(title, text) VALUES(?, ?)', ['Есть место, где заканчивается тротуар', 'Расти борода, расти'], - function(err) { + err => { if (err) { throw err; } @@ -39,30 +39,30 @@ connection.execute( 'Граждане Российской Федерации имеют право собираться мирно без оружия', 'проводить собрания, митинги и демонстрации, шествия и пикетирование' ], - function(err) { + err => { if (err) { throw err; } } ); -connection.execute('SELECT * FROM announcements', function(err, _rows) { +connection.execute('SELECT * FROM announcements', (err, _rows) => { rows = _rows; const s1 = connection.query('SELECT * FROM announcements').stream(); - s1.on('data', function(row) { + s1.on('data', row => { rows1.push(row); }); - s1.on('end', function() { + s1.on('end', () => { const s2 = connection.execute('SELECT * FROM announcements').stream(); - s2.on('data', function(row) { + s2.on('data', row => { rows2.push(row); }); - s2.on('end', function() { + s2.on('end', () => { connection.end(); }); }); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows.length, 2); assert.deepEqual(rows, rows1); assert.deepEqual(rows, rows2); diff --git a/test/integration/connection/test-then-on-query.js b/test/integration/connection/test-then-on-query.js index 1eb4a4a660..2f28eb8238 100644 --- a/test/integration/connection/test-then-on-query.js +++ b/test/integration/connection/test-then-on-query.js @@ -12,10 +12,10 @@ try { } catch (err) { error = false; } -q.on('end', function() { +q.on('end', () => { connection.destroy(); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(error, false); }); diff --git a/test/integration/connection/test-timestamp.js b/test/integration/connection/test-timestamp.js index e8e24e422a..b16deb286d 100644 --- a/test/integration/connection/test-timestamp.js +++ b/test/integration/connection/test-timestamp.js @@ -12,14 +12,14 @@ connection.query("INSERT INTO t VALUES('2013-01-22 01:02:03')"); let rows, fields; let rows1, fields1; let rows2; -connection.query('SELECT f FROM t', function(err, _rows, _fields) { +connection.query('SELECT f FROM t', (err, _rows, _fields) => { if (err) { throw err; } rows = _rows; fields = _fields; }); -connection.execute('SELECT f FROM t', function(err, _rows, _fields) { +connection.execute('SELECT f FROM t', (err, _rows, _fields) => { if (err) { throw err; } @@ -28,7 +28,7 @@ connection.execute('SELECT f FROM t', function(err, _rows, _fields) { }); // test 11-byte timestamp - https://github.com/sidorares/node-mysql2/issues/254 -connection.execute('SELECT CURRENT_TIMESTAMP(6) as t11', function(err, _rows) { +connection.execute('SELECT CURRENT_TIMESTAMP(6) as t11', (err, _rows) => { if (err) { throw err; } @@ -36,7 +36,7 @@ connection.execute('SELECT CURRENT_TIMESTAMP(6) as t11', function(err, _rows) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(rows[0].f.toString(), 'Invalid Date'); assert(rows[0].f instanceof Date); assert(rows[1].f instanceof Date); diff --git a/test/integration/connection/test-track-state-change.js b/test/integration/connection/test-track-state-change.js index e9e0486c1c..616e16f6a4 100644 --- a/test/integration/connection/test-track-state-change.js +++ b/test/integration/connection/test-track-state-change.js @@ -6,18 +6,18 @@ const assert = require('assert'); let result1, result2; -connection.query('SET NAMES koi8r', function(err, _ok) { +connection.query('SET NAMES koi8r', (err, _ok) => { assert.ifError(err); result1 = _ok; }); -connection.query('USE mysql', function(err, _ok) { +connection.query('USE mysql', (err, _ok) => { assert.ifError(err); result2 = _ok; connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.deepEqual(result1.stateChanges.systemVariables, { character_set_connection: 'koi8r', character_set_client: 'koi8r', diff --git a/test/integration/connection/test-transaction-commit.js b/test/integration/connection/test-transaction-commit.js index 8fa2c5b829..f50aa32d86 100644 --- a/test/integration/connection/test-transaction-commit.js +++ b/test/integration/connection/test-transaction-commit.js @@ -17,7 +17,7 @@ connection.query( ].join('\n') ); -connection.beginTransaction(function(err) { +connection.beginTransaction(err => { assert.ifError(err); const row = { @@ -25,13 +25,13 @@ connection.beginTransaction(function(err) { title: 'Test row' }; - connection.query('INSERT INTO ' + table + ' SET ?', row, function(err) { + connection.query('INSERT INTO ' + table + ' SET ?', row, err => { assert.ifError(err); - connection.commit(function(err) { + connection.commit(err => { assert.ifError(err); - connection.query('SELECT * FROM ' + table, function(err, rows) { + connection.query('SELECT * FROM ' + table, (err, rows) => { assert.ifError(err); connection.end(); assert.equal(rows.length, 1); diff --git a/test/integration/connection/test-transaction-rollback.js b/test/integration/connection/test-transaction-rollback.js index 00b730ce91..8ee18cb2e8 100644 --- a/test/integration/connection/test-transaction-rollback.js +++ b/test/integration/connection/test-transaction-rollback.js @@ -17,7 +17,7 @@ connection.query( ].join('\n') ); -connection.beginTransaction(function(err) { +connection.beginTransaction(err => { assert.ifError(err); const row = { @@ -25,13 +25,13 @@ connection.beginTransaction(function(err) { title: 'Test row' }; - connection.query('INSERT INTO ' + table + ' SET ?', row, function(err) { + connection.query('INSERT INTO ' + table + ' SET ?', row, err => { assert.ifError(err); - connection.rollback(function(err) { + connection.rollback(err => { assert.ifError(err); - connection.query('SELECT * FROM ' + table, function(err, rows) { + connection.query('SELECT * FROM ' + table, (err, rows) => { assert.ifError(err); connection.end(); assert.equal(rows.length, 0); diff --git a/test/integration/connection/test-type-cast-null-fields.js b/test/integration/connection/test-type-cast-null-fields.js index c93ee8ef8a..baf136e91e 100644 --- a/test/integration/connection/test-type-cast-null-fields.js +++ b/test/integration/connection/test-type-cast-null-fields.js @@ -24,7 +24,7 @@ connection.query('INSERT INTO ' + table + ' SET ?', { }); let results; -connection.query('SELECT * FROM ' + table, function(err, _results) { +connection.query('SELECT * FROM ' + table, (err, _results) => { if (err) { throw err; } @@ -33,7 +33,7 @@ connection.query('SELECT * FROM ' + table, function(err, _results) { connection.end(); }); -process.on('exit', function() { +process.on('exit', () => { assert.strictEqual(results[0].date, null); assert.strictEqual(results[0].number, null); }); diff --git a/test/integration/connection/test-type-casting.js b/test/integration/connection/test-type-casting.js index 5e9dc31402..6361f0ec4a 100644 --- a/test/integration/connection/test-type-casting.js +++ b/test/integration/connection/test-type-casting.js @@ -13,7 +13,7 @@ const table = 'type_casting'; const schema = []; const inserts = []; -tests.forEach(function(test, index) { +tests.forEach((test, index) => { const escaped = test.insertRaw || connection.escape(test.insert); test.columnName = test.type + '_' + index; @@ -35,7 +35,7 @@ connection.query(createTable); connection.query('INSERT INTO ' + table + ' SET' + inserts.join(',\n')); let row; -connection.query('SELECT * FROM type_casting', function(err, rows) { +connection.query('SELECT * FROM type_casting', (err, rows) => { if (err) { throw err; } @@ -44,8 +44,8 @@ connection.query('SELECT * FROM type_casting', function(err, rows) { connection.end(); }); -process.on('exit', function() { - tests.forEach(function(test) { +process.on('exit', () => { + tests.forEach(test => { let expected = test.expect || test.insert; let got = row[test.columnName]; let message; diff --git a/test/integration/connection/test-typecast-geometry.js b/test/integration/connection/test-typecast-geometry.js index 690c7acb6d..092521a8c6 100644 --- a/test/integration/connection/test-typecast-geometry.js +++ b/test/integration/connection/test-typecast-geometry.js @@ -14,7 +14,7 @@ connection.query( return next(); } }, - function(err, res) { + (err, res) => { assert.ifError(err); assert.deepEqual(res[0].foo, { x: 11, y: 0 }); } @@ -30,7 +30,7 @@ connection.query( return next(); } }, - function(err, res) { + (err, res) => { assert.ifError(err); assert.equal(Buffer.isBuffer(res[0].foo), true); } diff --git a/test/integration/connection/test-typecast.js b/test/integration/connection/test-typecast.js index bb8573b3bb..fa70c95647 100644 --- a/test/integration/connection/test-typecast.js +++ b/test/integration/connection/test-typecast.js @@ -14,7 +14,7 @@ connection.query( return next(); } }, - function(err, res) { + (err, res) => { assert.ifError(err); assert.equal(res[0].foo, 'FOO UPPERCASE'); } @@ -25,7 +25,7 @@ connection.query( sql: 'select "foobar" as foo', typeCast: false }, - function(err, res) { + (err, res) => { assert.ifError(err); assert(Buffer.isBuffer(res[0].foo)); assert.equal(res[0].foo.toString('utf8'), 'foobar'); @@ -39,7 +39,7 @@ connection.query( return next(); } }, - function(err, _rows) { + (err, _rows) => { assert.ifError(err); assert.equal(_rows[0].test, null); assert.equal(_rows[0].value, 6); diff --git a/test/integration/connection/test-update-changed-rows.js b/test/integration/connection/test-update-changed-rows.js index a03ed413c7..0cf2354690 100644 --- a/test/integration/connection/test-update-changed-rows.js +++ b/test/integration/connection/test-update-changed-rows.js @@ -27,19 +27,13 @@ connection.query('insert into changed_rows(value) values(1)'); connection.query('insert into changed_rows(value) values(2)'); connection.query('insert into changed_rows(value) values(3)'); -connection.execute('update changed_rows set value=1', [], function( - err, - _result -) { +connection.execute('update changed_rows set value=1', [], (err, _result) => { if (err) { throw err; } result1 = _result; - connection.execute('update changed_rows set value=1', [], function( - err, - _result - ) { + connection.execute('update changed_rows set value=1', [], (err, _result) => { if (err) { throw err; } @@ -49,7 +43,7 @@ connection.execute('update changed_rows set value=1', [], function( }); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(result1.affectedRows, 4); assert.equal(result1.changedRows, 2); assert.equal(result2.affectedRows, 4); diff --git a/test/integration/promise-wrappers/test-async-stack.js b/test/integration/promise-wrappers/test-async-stack.js index cca788d7ef..ea39eb45fe 100644 --- a/test/integration/promise-wrappers/test-async-stack.js +++ b/test/integration/promise-wrappers/test-async-stack.js @@ -60,7 +60,7 @@ function test() { test(); `; -process.on('unhandledRejection', function(err) { +process.on('unhandledRejection', err => { console.log(err.stack); }); diff --git a/test/integration/promise-wrappers/test-promise-wrappers.js b/test/integration/promise-wrappers/test-promise-wrappers.js index bb4f8fa431..dc6d649a36 100644 --- a/test/integration/promise-wrappers/test-promise-wrappers.js +++ b/test/integration/promise-wrappers/test-promise-wrappers.js @@ -23,22 +23,22 @@ let doneChangeUser = false; function testBasic() { let connResolved; createConnection(config) - .then(function(conn) { + .then(conn => { connResolved = conn; return conn.query('select 1+2 as ttt'); }) - .then(function(result1) { + .then(result1 => { assert.equal(result1[0][0].ttt, 3); return connResolved.query('select 2+2 as qqq'); }) - .then(function(result2) { + .then(result2 => { assert.equal(result2[0][0].qqq, 4); return connResolved.end(); }) - .then(function() { + .then(() => { doneCalled = true; }) - .catch(function(err) { + .catch(err => { throw err; }); } @@ -48,19 +48,19 @@ function testErrors() { const connPromise = createConnection(config); connPromise - .then(function(conn) { + .then(conn => { connResolved = conn; return conn.query('select 1+2 as ttt'); }) - .then(function(result1) { + .then(result1 => { assert.equal(result1[0][0].ttt, 3); return connResolved.query('bad sql'); }) - .then(function(result2) { + .then(result2 => { assert.equal(result2[0][0].ttt, 3); return connResolved.query('select 2+2 as qqq'); }) - .catch(function() { + .catch(() => { exceptionCaught = true; if (connResolved) { connResolved.end(); @@ -73,25 +73,25 @@ function testErrors() { function testObjParams() { let connResolved; createConnection(config) - .then(function(conn) { + .then(conn => { connResolved = conn; return conn.query({ sql: 'select ?-? as ttt', values: [5, 2] }); }) - .then(function(result1) { + .then(result1 => { assert.equal(result1[0][0].ttt, 3); return connResolved.execute({ sql: 'select ?-? as ttt', values: [8, 5] }); }) - .then(function(result2) { + .then(result2 => { assert.equal(result2[0][0].ttt, 3); return connResolved.end(); }) - .catch(function(err) { + .catch(err => { console.log(err); }); } @@ -99,19 +99,17 @@ function testObjParams() { function testPrepared() { let connResolved; createConnection(config) - .then(function(conn) { + .then(conn => { connResolved = conn; return conn.prepare('select ?-? as ttt, ? as uuu'); }) - .then(function(statement) { - return statement.execute([11, 3, 'test']); - }) - .then(function(result) { + .then(statement => statement.execute([11, 3, 'test'])) + .then(result => { assert.equal(result[0][0].ttt, 8); assert.equal(result[0][0].uuu, 'test'); return connResolved.end(); }) - .catch(function(err) { + .catch(err => { console.log(err); if (connResolved) { connResolved.end(); @@ -128,7 +126,7 @@ function testPrepared() { function testEventsConnect() { let connResolved; createConnection(config) - .then(function(conn) { + .then(conn => { connResolved = conn; let events = 0; @@ -147,6 +145,7 @@ function testEventsConnect() { ); } + /* eslint-disable no-invalid-this */ conn .once('error', function() { assert.equal(this, conn); @@ -170,6 +169,7 @@ function testEventsConnect() { doneEventsConnect = events === 5; }); + /* eslint-enable no-invalid-this */ conn.connection.emit('error', new Error()); conn.connection.emit('drain'); @@ -188,7 +188,7 @@ function testEventsConnect() { conn.end(); }) - .catch(function(err) { + .catch(err => { console.log(err); if (connResolved) { connResolved.end(); @@ -204,18 +204,18 @@ function testBasicPool() { const pool = createPool(config); pool .query('select 1+2 as ttt') - .then(function(result1) { + .then(result1 => { assert.equal(result1[0][0].ttt, 3); return pool.query('select 2+2 as qqq'); }) - .then(function(result2) { + .then(result2 => { assert.equal(result2[0][0].qqq, 4); return pool.end(); }) - .then(function() { + .then(() => { doneCalledPool = true; }) - .catch(function(err) { + .catch(err => { throw err; }); } @@ -224,15 +224,15 @@ function testErrorsPool() { const pool = createPool(config); pool .query('select 1+2 as ttt') - .then(function(result1) { + .then(result1 => { assert.equal(result1[0][0].ttt, 3); return pool.query('bad sql'); }) - .then(function(result2) { + .then(result2 => { assert.equal(result2[0][0].ttt, 3); return pool.query('select 2+2 as qqq'); }) - .catch(function() { + .catch(() => { exceptionCaughtPool = true; return pool.end(); }); @@ -245,18 +245,18 @@ function testObjParamsPool() { sql: 'select ?-? as ttt', values: [5, 2] }) - .then(function(result1) { + .then(result1 => { assert.equal(result1[0][0].ttt, 3); return pool.execute({ sql: 'select ?-? as ttt', values: [8, 5] }); }) - .then(function(result2) { + .then(result2 => { assert.equal(result2[0][0].ttt, 3); return pool.end(); }) - .catch(function(err) { + .catch(err => { console.log(err); }); } @@ -267,14 +267,14 @@ function testPromiseLibrary() { values: [8, 5] }); promise - .then(function() { + .then(() => { assert.ok(promise instanceof pool.Promise); }) - .then(function() { + .then(() => { promise = pool.end(); assert.ok(promise instanceof pool.Promise); }) - .catch(function(err) { + .catch(err => { console.log(err); }); } @@ -297,6 +297,7 @@ function testEventsPool() { ); } + /* eslint-disable no-invalid-this */ pool .once('acquire', function() { assert.equal(this, pool); @@ -316,6 +317,7 @@ function testEventsPool() { doneEventsPool = events === 4; }); + /* eslint-enable no-invalid-this */ pool.pool.emit('acquire'); pool.pool.emit('connection'); @@ -337,30 +339,26 @@ function testChangeUser() { }; let connResolved; createConnection(config) - .then(function(conn) { + .then(conn => { connResolved = conn; return connResolved.query( "GRANT ALL ON *.* TO 'changeuser1'@'%' IDENTIFIED BY 'changeuser1pass'" ); }) - .then(function() { - return connResolved.query( + .then(() => + connResolved.query( "GRANT ALL ON *.* TO 'changeuser2'@'%' IDENTIFIED BY 'changeuser2pass'" - ); - }) - .then(function() { - return connResolved.query('FLUSH PRIVILEGES'); - }) - .then(function() { - return connResolved.changeUser({ + ) + ) + .then(() => connResolved.query('FLUSH PRIVILEGES')) + .then(() => + connResolved.changeUser({ user: 'changeuser1', password: 'changeuser1pass' - }); - }) - .then(function() { - return connResolved.query('select current_user()'); - }) - .then(function(result) { + }) + ) + .then(() => connResolved.query('select current_user()')) + .then(result => { const rows = result[0]; assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser1'); return connResolved.changeUser({ @@ -368,10 +366,8 @@ function testChangeUser() { password: 'changeuser2pass' }); }) - .then(function() { - return connResolved.query('select current_user()'); - }) - .then(function(result) { + .then(() => connResolved.query('select current_user()')) + .then(result => { const rows = result[0]; assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser2'); return connResolved.changeUser({ @@ -382,16 +378,14 @@ function testChangeUser() { ) // sha1(changeuser1pass) }); }) - .then(function() { - return connResolved.query('select current_user()'); - }) - .then(function(result) { + .then(() => connResolved.query('select current_user()')) + .then(result => { const rows = result[0]; assert.deepEqual(onlyUsername(rows[0]['current_user()']), 'changeuser1'); doneChangeUser = true; return connResolved.end(); }) - .catch(function(err) { + .catch(err => { if (connResolved) { connResolved.end(); } @@ -443,7 +437,7 @@ testChangeUser(); testPoolConnectionDestroy(); testPromiseLibrary(); -process.on('exit', function() { +process.on('exit', () => { assert.equal(doneCalled, true, 'done not called'); assert.equal(exceptionCaught, true, 'exception not caught'); assert.equal(doneEventsConnect, true, 'wrong number of connection events'); @@ -453,6 +447,6 @@ process.on('exit', function() { assert.equal(doneChangeUser, true, 'user not changed'); }); -process.on('unhandledRejection', function(err) { +process.on('unhandledRejection', err => { console.log('AAA', err.stack); }); diff --git a/test/integration/regressions/test-#433.js b/test/integration/regressions/test-#433.js index 75be0c3d1a..5a47d8b9f3 100644 --- a/test/integration/regressions/test-#433.js +++ b/test/integration/regressions/test-#433.js @@ -14,7 +14,7 @@ let actualError = null; function executeErrorMessageTest() { // tableName does not have closing "`", we do this to have tableName in error string // it is sent back in original encoding (koi8r), we are testing that it's decoded correctly - connection.query('SELECT * FROM `' + tableName, function(err) { + connection.query('SELECT * FROM `' + tableName, err => { actualError = err.message; connection.end(); }); @@ -22,7 +22,7 @@ function executeErrorMessageTest() { function executeTest(err) { assert.ifError(err); - connection.query('SELECT * FROM `' + tableName + '`', function(err, rows) { + connection.query('SELECT * FROM `' + tableName + '`', (err, rows) => { assert.ifError(err); actualRows = rows; executeErrorMessageTest(); @@ -39,7 +39,7 @@ connection.query( ' PRIMARY KEY (`' + testFields[0] + '`)', ') ENGINE=InnoDB DEFAULT CHARSET=utf8' ].join(' '), - function(err) { + err => { assert.ifError(err); connection.query( [ @@ -72,8 +72,8 @@ connection.query( const expectedError = "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`МояТаблица' at line 1"; -process.on('exit', function() { - testRows.map(function(tRow, index) { +process.on('exit', () => { + testRows.map((tRow, index) => { const cols = testFields; const aRow = actualRows[index]; assert.equal(aRow[cols[0]], tRow[0]); diff --git a/test/integration/regressions/test-#442.js b/test/integration/regressions/test-#442.js index 6cac026e0d..98c663ba4d 100644 --- a/test/integration/regressions/test-#442.js +++ b/test/integration/regressions/test-#442.js @@ -12,7 +12,7 @@ let actualRows = null; function executeTest(err) { assert.ifError(err); - connection.query('SELECT * FROM `' + tableName + '`', function(err, rows) { + connection.query('SELECT * FROM `' + tableName + '`', (err, rows) => { assert.ifError(err); actualRows = rows; connection.end(); @@ -29,7 +29,7 @@ connection.query( ' PRIMARY KEY (`' + testFields[0] + '`)', ') ENGINE=InnoDB DEFAULT CHARSET=utf8' ].join(' '), - function(err) { + err => { assert.ifError(err); connection.query( [ @@ -58,8 +58,8 @@ connection.query( } ); -process.on('exit', function() { - testRows.map(function(tRow, index) { +process.on('exit', () => { + testRows.map((tRow, index) => { const cols = testFields; const aRow = actualRows[index]; assert.equal(aRow[cols[0]], tRow[0]); diff --git a/test/integration/regressions/test-#485.js b/test/integration/regressions/test-#485.js index 1f5a853696..b2aa1e58e8 100644 --- a/test/integration/regressions/test-#485.js +++ b/test/integration/regressions/test-#485.js @@ -17,18 +17,18 @@ function testPoolPromiseExecuteLeak() { const pool = createPool(config); pool .execute('select 1+2 as ttt') - .then(function(result) { + .then(result => { assert.equal(result[0][0].ttt, 3); return pool.end(); }) - .catch(function(err) { + .catch(err => { assert.ifError(err); }); } testPoolPromiseExecuteLeak(); -process.on('exit', function() { +process.on('exit', () => { PoolConnection.prototype.release = release; assert.equal(releaseCalls, 1, 'PoolConnection.release was not called'); }); diff --git a/test/integration/regressions/test-#617.js b/test/integration/regressions/test-#617.js index 0859cd67bd..7d144bc323 100644 --- a/test/integration/regressions/test-#617.js +++ b/test/integration/regressions/test-#617.js @@ -27,7 +27,7 @@ let actualRows = null; function executeTest(err) { assert.ifError(err); - connection.execute('SELECT * FROM `' + tableName + '`', function(err, rows) { + connection.execute('SELECT * FROM `' + tableName + '`', (err, rows) => { assert.ifError(err); actualRows = rows; connection.end(); @@ -42,7 +42,7 @@ connection.query( ' `' + testFields[2] + '` varchar(10)', ') ENGINE=InnoDB DEFAULT CHARSET=utf8' ].join(' '), - function(err) { + err => { assert.ifError(err); connection.query( [ @@ -67,10 +67,10 @@ connection.query( } ); -process.on('exit', function() { - expected.map(function(exp, index) { +process.on('exit', () => { + expected.map((exp, index) => { const row = actualRows[index]; - Object.keys(exp).map(function(key) { + Object.keys(exp).map(key => { assert.equal(exp[key], row[key]); }); }); diff --git a/test/integration/regressions/test-#629.js b/test/integration/regressions/test-#629.js index 5151138fa0..c08bc51396 100644 --- a/test/integration/regressions/test-#629.js +++ b/test/integration/regressions/test-#629.js @@ -29,7 +29,7 @@ let actualRows = null; function executeTest(err) { assert.ifError(err); - connection.execute('SELECT * FROM `' + tableName + '`', function(err, rows) { + connection.execute('SELECT * FROM `' + tableName + '`', (err, rows) => { assert.ifError(err); actualRows = rows; connection.end(); @@ -45,7 +45,7 @@ connection.query( ' `' + testFields[3] + '` varchar(10)', ') ENGINE=InnoDB DEFAULT CHARSET=utf8' ].join(' '), - function(err) { + err => { assert.ifError(err); connection.query( [ @@ -74,10 +74,10 @@ connection.query( } ); -process.on('exit', function() { - expected.map(function(exp, index) { +process.on('exit', () => { + expected.map((exp, index) => { const row = actualRows[index]; - Object.keys(exp).map(function(key) { + Object.keys(exp).map(key => { if (key.startsWith('date')) { assert.equal(+exp[key], +row[key]); } else { diff --git a/test/integration/regressions/test-#82.js b/test/integration/regressions/test-#82.js index 56bebd7853..98fc6c2e4f 100644 --- a/test/integration/regressions/test-#82.js +++ b/test/integration/regressions/test-#82.js @@ -55,11 +55,11 @@ const prepareTestSet = function(cb) { ); }; -prepareTestSet(function(err) { +prepareTestSet(err => { assert.ifError(err); connection.query( 'select * from ' + config.view2 + ' order by name2 desc', - function(err, rows) { + (err, rows) => { assert.ifError(err); results = rows; connection.close(); @@ -67,7 +67,7 @@ prepareTestSet(function(err) { ); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(results[0].name1, 'D'); assert.equal(results[1].name1, 'C'); assert.equal(results[2].name1, 'B'); diff --git a/test/integration/test-auth-switch.js b/test/integration/test-auth-switch.js index c3f61029fa..fac0b2d3f2 100644 --- a/test/integration/test-auth-switch.js +++ b/test/integration/test-auth-switch.js @@ -25,7 +25,7 @@ class TestAuthSwitchHandshake extends Command { capabilityFlags: 0xffffff }); this.serverHello = serverHelloPacket; - serverHelloPacket.setScrambleData(function() { + serverHelloPacket.setScrambleData(() => { connection.writePacket(serverHelloPacket.toPacket(0)); }); return TestAuthSwitchHandshake.prototype.readClientReply; @@ -65,7 +65,7 @@ class TestAuthSwitchHandshake extends Command { } } -const server = mysql.createServer(function(conn) { +const server = mysql.createServer(conn => { conn.serverConfig = {}; conn.serverConfig.encoding = 'cesu8'; conn.addCommand( @@ -79,7 +79,7 @@ const server = mysql.createServer(function(conn) { // REVIEW: Unused var const portfinder = require('portfinder'); -portfinder.getPort(function(err, port) { +portfinder.getPort((err, port) => { const makeSwitchHandler = function() { let count = 0; return function(data, cb) { @@ -104,7 +104,7 @@ portfinder.getPort(function(err, port) { connectAttributes: connectAttributes }); - conn.on('connect', function(data) { + conn.on('connect', data => { assert.equal(data.serverVersion, 'node.js rocks'); assert.equal(data.connectionId, 1234); diff --git a/test/integration/test-namedPlaceholders.js b/test/integration/test-namedPlaceholders.js index 9f0f3423e8..2a8e050154 100644 --- a/test/integration/test-namedPlaceholders.js +++ b/test/integration/test-namedPlaceholders.js @@ -12,7 +12,7 @@ test('Test namedPlaceholder as command parameter', { 'Enabled in connection config, disabled in query command': () => { // enabled in initial config, disable in test const c = createConnection({ namedPlaceholders: true }); - c.query({ sql: query, namedPlaceholders: false }, values, function(err) { + c.query({ sql: query, namedPlaceholders: false }, values, err => { if (!err || !err.sqlMessage.match(/right syntax to use near ':named'/)) { assert.fail( 'Expected err.sqlMessage to contain "right syntax to use near \':named\'" sqlMessage: ' + @@ -24,10 +24,7 @@ test('Test namedPlaceholder as command parameter', { }, 'Disabled in connection config, enable query command': () => { const c = createConnection({ namedPlaceholders: false }); - c.query({ sql: query, namedPlaceholders: true }, values, function( - err, - rows - ) { + c.query({ sql: query, namedPlaceholders: true }, values, (err, rows) => { assert.ifError(err); assert.equal(rows[0].result, 1); c.end(); @@ -35,10 +32,7 @@ test('Test namedPlaceholder as command parameter', { }, 'Disabled in connection config, enable execute command': () => { const c = createConnection({ namedPlaceholders: false }); - c.execute({ sql: query, namedPlaceholders: true }, values, function( - err, - rows - ) { + c.execute({ sql: query, namedPlaceholders: true }, values, (err, rows) => { assert.ifError(err); assert.equal(rows[0].result, 1); c.end(); diff --git a/test/integration/test-pool-connect-error.js b/test/integration/test-pool-connect-error.js index cdfbc1b908..72e5cb2e08 100644 --- a/test/integration/test-pool-connect-error.js +++ b/test/integration/test-pool-connect-error.js @@ -4,7 +4,7 @@ const mysql = require('../../index.js'); const assert = require('assert'); -const server = mysql.createServer(function(conn) { +const server = mysql.createServer(conn => { conn.serverHandshake({ protocolVersion: 10, serverVersion: '5.6.10', @@ -21,7 +21,7 @@ const server = mysql.createServer(function(conn) { let err1, err2; const portfinder = require('portfinder'); -portfinder.getPort(function(err, port) { +portfinder.getPort((err, port) => { server.listen(port); const conn = mysql.createConnection({ user: 'test_user', @@ -29,7 +29,7 @@ portfinder.getPort(function(err, port) { database: 'test_database', port: port }); - conn.on('error', function(err) { + conn.on('error', err => { err1 = err; }); @@ -40,14 +40,14 @@ portfinder.getPort(function(err, port) { port: port }); - pool.query('test sql', function(err) { + pool.query('test sql', err => { err2 = err; pool.end(); server.close(); }); }); -process.on('exit', function() { +process.on('exit', () => { assert.equal(err1.errno, 1040); assert.equal(err2.errno, 1040); }); diff --git a/test/integration/test-pool-disconnect.js b/test/integration/test-pool-disconnect.js index 5fe248bab5..f32e515d08 100644 --- a/test/integration/test-pool-disconnect.js +++ b/test/integration/test-pool-disconnect.js @@ -13,12 +13,12 @@ let numSelects = 0; let killCount = 0; function kill() { - setTimeout(function() { + setTimeout(() => { const id = tids.shift(); if (typeof id != 'undefined') { // sleep required to give mysql time to close connection, // and callback called after connection with id is really closed - conn.query('kill ?; select sleep(0.05)', id, function(err) { + conn.query('kill ?; select sleep(0.05)', id, err => { assert.ifError(err); killCount++; // TODO: this assertion needs to be fixed, after kill @@ -33,15 +33,15 @@ function kill() { }, 5); } -pool.on('connection', function(conn) { +pool.on('connection', conn => { tids.push(conn.threadId); - conn.on('error', function() { + conn.on('error', () => { setTimeout(kill, 5); }); }); for (let i = 0; i < numSelectToPerform; i++) { - pool.query('select 1 as value', function(err, rows) { + pool.query('select 1 as value', (err, rows) => { numSelects++; assert.ifError(err); assert.equal(rows[0].value, 1); @@ -53,7 +53,7 @@ for (let i = 0; i < numSelectToPerform; i++) { }); } -process.on('exit', function() { +process.on('exit', () => { assert.equal(numSelects, numSelectToPerform); assert.equal(killCount, pool.config.connectionLimit); }); diff --git a/test/integration/test-pool-release.js b/test/integration/test-pool-release.js index e181ac2eb6..d74c6f4af9 100644 --- a/test/integration/test-pool-release.js +++ b/test/integration/test-pool-release.js @@ -5,18 +5,18 @@ const assert = require('assert'); const pool = createPool(); -pool.query('test sql', function() { - pool.query('test sql', [], function() { - pool.query('test sql', [], function() { - pool.query('test sql', [], function() { - pool.query('test sql', function() { - pool.query('test sql').on('error', function() { - pool.query('test sql', function() { - pool.execute('test sql', function() { - pool.execute('test sql', function() { - pool.execute('test sql', [], function() { - pool.execute('test sql', function() { - pool.execute('test sql', function() { +pool.query('test sql', () => { + pool.query('test sql', [], () => { + pool.query('test sql', [], () => { + pool.query('test sql', [], () => { + pool.query('test sql', () => { + pool.query('test sql').on('error', () => { + pool.query('test sql', () => { + pool.execute('test sql', () => { + pool.execute('test sql', () => { + pool.execute('test sql', [], () => { + pool.execute('test sql', () => { + pool.execute('test sql', () => { // TODO change order events are fires so that connection is released before callback // that way this number will be more deterministic assert(pool._allConnections.length < 3); diff --git a/test/integration/test-rows-as-array.js b/test/integration/test-rows-as-array.js index c442c45c46..042f60d20f 100644 --- a/test/integration/test-rows-as-array.js +++ b/test/integration/test-rows-as-array.js @@ -5,22 +5,22 @@ const assert = require('assert'); // enabled in initial config, disable in some tets const c = createConnection({ rowsAsArray: true }); -c.query('select 1+1 as a', function(err, rows) { +c.query('select 1+1 as a', (err, rows) => { assert.ifError(err); assert.equal(rows[0][0], 2); }); -c.query({ sql: 'select 1+2 as a', rowsAsArray: false }, function(err, rows) { +c.query({ sql: 'select 1+2 as a', rowsAsArray: false }, (err, rows) => { assert.ifError(err); assert.equal(rows[0].a, 3); }); -c.execute('select 1+1 as a', function(err, rows) { +c.execute('select 1+1 as a', (err, rows) => { assert.ifError(err); assert.equal(rows[0][0], 2); }); -c.execute({ sql: 'select 1+2 as a', rowsAsArray: false }, function(err, rows) { +c.execute({ sql: 'select 1+2 as a', rowsAsArray: false }, (err, rows) => { assert.ifError(err); assert.equal(rows[0].a, 3); c.end(); @@ -28,22 +28,22 @@ c.execute({ sql: 'select 1+2 as a', rowsAsArray: false }, function(err, rows) { // disabled in initial config, enable in some tets const c1 = createConnection({ rowsAsArray: false }); -c1.query('select 1+1 as a', function(err, rows) { +c1.query('select 1+1 as a', (err, rows) => { assert.ifError(err); assert.equal(rows[0].a, 2); }); -c1.query({ sql: 'select 1+2 as a', rowsAsArray: true }, function(err, rows) { +c1.query({ sql: 'select 1+2 as a', rowsAsArray: true }, (err, rows) => { assert.ifError(err); assert.equal(rows[0][0], 3); }); -c1.execute('select 1+1 as a', function(err, rows) { +c1.execute('select 1+1 as a', (err, rows) => { assert.ifError(err); assert.equal(rows[0].a, 2); }); -c1.execute({ sql: 'select 1+2 as a', rowsAsArray: true }, function(err, rows) { +c1.execute({ sql: 'select 1+2 as a', rowsAsArray: true }, (err, rows) => { assert.ifError(err); assert.equal(rows[0][0], 3); c1.end(); diff --git a/test/run.js b/test/run.js index 1453e16730..d75d4758be 100755 --- a/test/run.js +++ b/test/run.js @@ -15,14 +15,14 @@ process.env.TZ = 'UTC'; require('urun')(__dirname, options); -process.on('exit', function(code) { +process.on('exit', code => { console.log('About to exit with code: ' + code); }); -process.on('unhandledRejection', function(reason) { +process.on('unhandledRejection', reason => { console.log('unhandledRejection', reason); }); -process.on('uncaughtException', function(err) { +process.on('uncaughtException', err => { console.log('uncaughtException', err); }); diff --git a/test/unit/test-packet-parser.js b/test/unit/test-packet-parser.js index c9465d6e67..1a0cbb04dc 100644 --- a/test/unit/test-packet-parser.js +++ b/test/unit/test-packet-parser.js @@ -17,9 +17,7 @@ function reset() { function execute(str, verify) { reset(); - const buffers = str.split('|').map(function(sb) { - return sb.split(',').map(Number); - }); + const buffers = str.split('|').map(sb => sb.split(',').map(Number)); for (let i = 0; i < buffers.length; ++i) { pp.execute(Buffer.from(buffers[i])); } @@ -33,7 +31,7 @@ function p123() { } function p120_121() { - packets.forEach(function(p) { + packets.forEach(p => { p.dump; }); assert(packets.length === 2); @@ -99,10 +97,10 @@ p.writeHeader(42); function testBigPackets(chunks, cb) { const packets = []; - const pp = new PacketParser(function(p) { + const pp = new PacketParser(p => { packets.push(p); }); - chunks.forEach(function(ch) { + chunks.forEach(ch => { pp.execute(ch); }); cb(packets);