Skip to content

Commit

Permalink
Merge pull request #870 from SimonSchick/chore/es6-arrow
Browse files Browse the repository at this point in the history
chore: use es6 arrows function
  • Loading branch information
sidorares authored Nov 17, 2018
2 parents 392e9a1 + 6571b87 commit 0c422dd
Show file tree
Hide file tree
Showing 148 changed files with 899 additions and 995 deletions.
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
42 changes: 21 additions & 21 deletions benchmarks/FB/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (cluster.isMaster) {
cluster.fork();
}

cluster.on('exit', function(worker) {
cluster.on('exit', worker => {
console.log('worker ' + worker.pid + ' died');
});

Expand Down Expand Up @@ -58,7 +58,7 @@ function getRandomNumber() {
}

function sequelizeQuery(callback) {
World.findById(getRandomNumber(), function(err, world) {
World.findById(getRandomNumber(), (err, world) => {
callback(null, world);
});
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
});
Expand All @@ -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.'
Expand All @@ -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.'
Expand All @@ -166,7 +166,7 @@ function fortuneMaria(res) {
}

http
.createServer(function(req, res) {
.createServer((req, res) => {
// JSON response object
const hello = { message: 'Hello, world' };

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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.');
Expand Down Expand Up @@ -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;
}
Expand All @@ -297,7 +297,7 @@ http
rows[0].randomNumber +
' WHERE id = ' +
rows[0]['id'],
function(err) {
err => {
if (err) {
throw err;
}
Expand All @@ -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.');
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/bench-fake-server-maria.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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(
Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/bench-fake-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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(
Expand All @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/bench-insert-select-parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '` (',
Expand All @@ -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();
Expand All @@ -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');
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions benchmarks/bench-insert-select-prepared.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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');
Expand All @@ -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();
Expand All @@ -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(
Expand All @@ -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();
Expand Down
18 changes: 8 additions & 10 deletions benchmarks/bench-insert-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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');
Expand All @@ -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();
Expand All @@ -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(
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmark-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 0c422dd

Please sign in to comment.