Skip to content

Commit c7cb688

Browse files
committed
clean up formatting
1 parent 0004c60 commit c7cb688

11 files changed

+67
-92
lines changed

benchmarks/bench-insert-select-parallel.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ connection.query(
1818
);
1919

2020
function benchmarkInsert(numLeft, callback) {
21-
connection.query(`INSERT INTO ${table} SET title="${text}"`, err => {
22-
if (err) throw err;
23-
if (numLeft > 1) benchmarkInsert(numLeft - 1, callback);
24-
else callback();
25-
});
21+
connection.query(
22+
`INSERT INTO ${table} SET title="${text}"`,
23+
err => {
24+
if (err) throw err;
25+
if (numLeft > 1) benchmarkInsert(numLeft - 1, callback);
26+
else callback();
27+
}
28+
);
2629
}
2730

2831
function benchmarkInserts(n, cb) {
@@ -48,8 +51,7 @@ function benchmarkParallelSelects(n, size, cb) {
4851
const end = process.hrtime();
4952
const diff = common.hrdiff(start, end);
5053
console.log(
51-
`${size} rows: ${(n * 1e9) / diff} results/sec, ${(size * n * 1e9) /
52-
diff} rows/sec`
54+
`${size} rows: ${(n * 1e9) / diff} results/sec, ${(size * n * 1e9) / diff} rows/sec`
5355
);
5456
cb();
5557
}

benchmarks/bench-insert-select-prepared.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ connection.query(
1717
);
1818

1919
function benchmarkInsert(numLeft, callback) {
20-
connection.execute(`INSERT INTO ${table} SET title="${text}"`, [], err => {
21-
if (err) throw err;
22-
if (numLeft > 1) benchmarkInsert(numLeft - 1, callback);
23-
else callback();
24-
});
20+
connection.execute(
21+
`INSERT INTO ${table} SET title="${text}"`,
22+
[],
23+
err => {
24+
if (err) throw err;
25+
if (numLeft > 1) benchmarkInsert(numLeft - 1, callback);
26+
else callback();
27+
}
28+
);
2529
}
2630

2731
function benchmarkInserts(n, cb) {
@@ -37,11 +41,15 @@ function benchmarkInserts(n, cb) {
3741
}
3842

3943
function benchmarkSelect(numLeft, numSelect, callback) {
40-
connection.execute(`select * from ${table} limit ${numSelect}`, [], err => {
41-
if (err) throw err;
42-
if (numLeft > 1) benchmarkSelect(numLeft - 1, numSelect, callback);
43-
else callback();
44-
});
44+
connection.execute(
45+
`select * from ${table} limit ${numSelect}`,
46+
[],
47+
err => {
48+
if (err) throw err;
49+
if (numLeft > 1) benchmarkSelect(numLeft - 1, numSelect, callback);
50+
else callback();
51+
}
52+
);
4553
}
4654

4755
function benchmarkSelects(n, size, cb) {
@@ -51,10 +59,7 @@ function benchmarkSelects(n, size, cb) {
5159
const end = process.hrtime();
5260
const diff = common.hrdiff(start, end);
5361
console.log(
54-
`${size} rows: ${(numSelects * 1e9) / diff} results/sec, ${(size *
55-
numSelects *
56-
1e9) /
57-
diff} rows/sec`
62+
`${size} rows: ${(numSelects * 1e9) / diff} results/sec, ${(size * numSelects * 1e9) / diff} rows/sec`
5863
);
5964
if (n > 1) benchmarkSelects(n - 1, size, cb);
6065
else cb();

benchmarks/bench-insert-select.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ connection.query(
1616
);
1717

1818
function benchmarkInsert(numLeft, callback) {
19-
connection.query(`INSERT INTO ${table} SET title="${text}"`, err => {
20-
if (err) throw err;
21-
if (numLeft > 1) benchmarkInsert(numLeft - 1, callback);
22-
else callback();
23-
});
19+
connection.query(
20+
`INSERT INTO ${table} SET title="${text}"`,
21+
err => {
22+
if (err) throw err;
23+
if (numLeft > 1) benchmarkInsert(numLeft - 1, callback);
24+
else callback();
25+
}
26+
);
2427
}
2528

2629
function benchmarkInserts(n, cb) {
@@ -50,10 +53,7 @@ function benchmarkSelects(n, size, cb) {
5053
const end = process.hrtime();
5154
const diff = common.hrdiff(start, end);
5255
console.log(
53-
`${size} rows: ${(numSelects * 1e9) / diff} results/sec, ${(size *
54-
numSelects *
55-
1e9) /
56-
diff} rows/sec`
56+
`${size} rows: ${(numSelects * 1e9) / diff} results/sec, ${(size * numSelects * 1e9) / diff} rows/sec`
5757
);
5858
if (n > 1) benchmarkSelects(n - 1, size, cb);
5959
else cb();

lib/commands/auth_switch.js

-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ const standardAuthPlugins = {
1919
};
2020

2121
function warnLegacyAuthSwitch() {
22-
/* eslint-disable no-console */
2322
console.warn(
2423
'WARNING! authSwitchHandler api is deprecated, please use new authPlugins api'
2524
);
26-
/* eslint-enable no-console */
2725
}
2826

2927
function authSwitchPluginError(error, command) {

lib/commands/query.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ class Query extends Command {
120120
if (connection.config.debug) {
121121
// eslint-disable-next-line
122122
console.log(
123-
` Resultset header received, expecting ${
124-
rs.fieldCount
125-
} column definition packets`
123+
` Resultset header received, expecting ${rs.fieldCount} column definition packets`
126124
);
127125
}
128126
if (this._fieldCount === 0) {

lib/connection.js

+9-39
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,11 @@ class Connection extends EventEmitter {
299299
if (this.config.debug) {
300300
// eslint-disable-next-line no-console
301301
console.log(
302-
`${this._internalId} ${this.connectionId} <== ${
303-
this._command._commandName
304-
}#${this._command.stateName()}(${[
305-
this.sequenceId,
306-
packet._name,
307-
packet.length()
308-
].join(',')})`
302+
`${this._internalId} ${this.connectionId} <== ${this._command._commandName}#${this._command.stateName()}(${[this.sequenceId, packet._name, packet.length()].join(',')})`
309303
);
310304
// eslint-disable-next-line no-console
311305
console.log(
312-
`${this._internalId} ${
313-
this.connectionId
314-
} <== ${packet.buffer.toString('hex')}`
306+
`${this._internalId} ${this.connectionId} <== ${packet.buffer.toString('hex')}`
315307
);
316308
}
317309
this._bumpSequenceId(1);
@@ -320,19 +312,11 @@ class Connection extends EventEmitter {
320312
if (this.config.debug) {
321313
// eslint-disable-next-line no-console
322314
console.log(
323-
`${this._internalId} ${
324-
this.connectionId
325-
} <== Writing large packet, raw content not written:`
315+
`${this._internalId} ${this.connectionId} <== Writing large packet, raw content not written:`
326316
);
327317
// eslint-disable-next-line no-console
328318
console.log(
329-
`${this._internalId} ${this.connectionId} <== ${
330-
this._command._commandName
331-
}#${this._command.stateName()}(${[
332-
this.sequenceId,
333-
packet._name,
334-
packet.length()
335-
].join(',')})`
319+
`${this._internalId} ${this.connectionId} <== ${this._command._commandName}#${this._command.stateName()}(${[this.sequenceId, packet._name, packet.length()].join(',')})`
336320
);
337321
}
338322
for (offset = 4; offset < 4 + length; offset += MAX_PACKET_LENGTH) {
@@ -441,9 +425,7 @@ class Connection extends EventEmitter {
441425
if (packet) {
442426
// eslint-disable-next-line no-console
443427
console.log(
444-
` raw: ${packet.buffer
445-
.slice(packet.offset, packet.offset + packet.length())
446-
.toString('hex')}`
428+
` raw: ${packet.buffer.slice(packet.offset, packet.offset + packet.length()).toString('hex')}`
447429
);
448430
// eslint-disable-next-line no-console
449431
console.trace();
@@ -455,13 +437,7 @@ class Connection extends EventEmitter {
455437
: '(no command)';
456438
// eslint-disable-next-line no-console
457439
console.log(
458-
`${this._internalId} ${
459-
this.connectionId
460-
} ==> ${commandName}#${stateName}(${[
461-
packet.sequenceId,
462-
packet.type(),
463-
packet.length()
464-
].join(',')})`
440+
`${this._internalId} ${this.connectionId} ==> ${commandName}#${stateName}(${[packet.sequenceId, packet.type(), packet.length()].join(',')})`
465441
);
466442
}
467443
}
@@ -597,9 +573,7 @@ class Connection extends EventEmitter {
597573
cmdQuery.values !== undefined ? cmdQuery.values : []
598574
);
599575
cmdQuery.sql = rawSql;
600-
// eslint-disable-next-line consistent-this, no-invalid-this
601-
const self = this;
602-
cmdQuery.once('end', () => self.emit('done'));
576+
cmdQuery.once('end', () => this.emit('done'));
603577
return this.addCommand(cmdQuery);
604578
}
605579

@@ -720,9 +694,7 @@ class Connection extends EventEmitter {
720694
});
721695
this.addCommand(prepareCommand);
722696
this.addCommand(executeCommand);
723-
// eslint-disable-next-line consistent-this, no-invalid-this
724-
const self = this;
725-
executeCommand.once('end', () => self.emit('done'));
697+
executeCommand.once('end', () => this.emit('done'));
726698
return executeCommand;
727699
}
728700

@@ -970,9 +942,7 @@ class Connection extends EventEmitter {
970942
}
971943

972944
static statementKey(options) {
973-
return `${typeof options.nestTables}/${options.nestTables}/${
974-
options.rowsAsArray
975-
}${options.sql}`;
945+
return `${typeof options.nestTables}/${options.nestTables}/${options.rowsAsArray}${options.sql}`;
976946
}
977947
}
978948

lib/connection_config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ class ConnectionConfig {
127127
// https://github.com/mysqljs/mysql#user-content-connection-options
128128
// eslint-disable-next-line no-console
129129
console.error(
130-
`Ignoring invalid timezone passed to Connection: ${
131-
options.timezone
132-
}. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection`
130+
`Ignoring invalid timezone passed to Connection: ${options.timezone}. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection`
133131
);
134132
// SqlStrings falls back to UTC on invalid timezone
135133
this.timezone = 'Z';

lib/pool.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ class Pool extends EventEmitter {
143143
return;
144144
}
145145
try {
146-
conn.query(cmdQuery);
147-
conn.once('done', () => conn.release());
146+
conn.query(cmdQuery).once('end', () => {
147+
conn.release();
148+
});
148149
} catch (e) {
149150
conn.release();
150151
throw e;
@@ -178,8 +179,9 @@ class Pool extends EventEmitter {
178179
return cb(err);
179180
}
180181
try {
181-
conn.execute(sql, values, cb);
182-
conn.once('done', () => conn.release());
182+
conn.execute(sql, values, cb).once('end', () => {
183+
conn.release();
184+
});
183185
} catch (e) {
184186
conn.release();
185187
return cb(e);

lib/pool_cluster.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ class PoolCluster extends EventEmitter {
182182
callback !== undefined
183183
? callback
184184
: err => {
185-
if (err /* eslint-disable-line */) {
186-
throw err; /* eslint-disable-line */
187-
} /* eslint-disable-line */
188-
}; /* eslint-disable-line */
185+
if (err) {
186+
throw err;
187+
}
188+
};
189189
if (this._closed) {
190190
process.nextTick(cb);
191191
return;

lib/results_stream.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ const Readable = require('stream').Readable;
55
// copy-paste from https://github.com/mysqljs/mysql/blob/master/lib/protocol/sequences/Query.js
66
module.exports = function(command, connectionStream) {
77
command.stream = function(options) {
8+
let stream;
9+
810
options = options || {};
911
options.objectMode = true;
10-
const stream = new Readable(options);
11-
stream._read = function() {
12+
(stream = new Readable(options)),
13+
(stream._read = function() {
1214
connectionStream.resume();
13-
};
15+
});
1416

1517
this.on('result', (row, i) => {
1618
if (!stream.push(row)) {

promise.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,11 @@ class PromisePool extends EventEmitter {
370370
'Callback function is not available with promise clients.'
371371
);
372372
}
373-
return this.getConnection().then(async conn => {
373+
return this.getConnection().then(conn => {
374374
try {
375375
const promise = conn.query(sql, args);
376376
conn.once('done', () => conn.release());
377-
return await promise;
377+
return promise;
378378
} catch (e) {
379379
conn.release();
380380
throw e;
@@ -388,11 +388,11 @@ class PromisePool extends EventEmitter {
388388
'Callback function is not available with promise clients.'
389389
);
390390
}
391-
return this.getConnection().then(async conn => {
391+
return this.getConnection().then(conn => {
392392
try {
393393
const promise = conn.execute(sql, args);
394394
conn.once('done', () => conn.release());
395-
return await promise;
395+
return promise;
396396
} catch (e) {
397397
conn.release();
398398
throw e;

0 commit comments

Comments
 (0)