Skip to content

Commit 5f0fb8f

Browse files
authored
add prettier and wait for db to go live before starting tests
1 parent 0fa5282 commit 5f0fb8f

File tree

160 files changed

+4606
-3174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+4606
-3174
lines changed

.eslintrc

Lines changed: 8 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,15 @@
11
{
2+
"extends": [
3+
"prettier"
4+
],
5+
"parserOptions": {
6+
"ecmaVersion": 7,
7+
},
28
"plugins": [
3-
"markdown"
9+
"markdown",
10+
"async-await"
411
],
512
"env": {
613
"node": true
7-
},
8-
"rules": {
9-
"array-bracket-spacing": [
10-
2,
11-
"never"
12-
],
13-
"block-spacing": [
14-
2,
15-
"always"
16-
],
17-
"comma-dangle": [
18-
2,
19-
"never"
20-
],
21-
"comma-spacing": [
22-
2,
23-
{
24-
"after": true,
25-
"before": false
26-
}
27-
],
28-
"computed-property-spacing": [
29-
2,
30-
"never"
31-
],
32-
"consistent-return": 2,
33-
"curly": 2,
34-
"eol-last": 2,
35-
"indent": [
36-
2,
37-
2
38-
],
39-
"keyword-spacing": [
40-
2,
41-
{
42-
"after": true,
43-
"before": true
44-
}
45-
],
46-
"linebreak-style": [
47-
2,
48-
"unix"
49-
],
50-
"no-cond-assign": 2,
51-
"no-constant-condition": 2,
52-
"no-control-regex": 2,
53-
"no-debugger": 2,
54-
"no-dupe-args": 2,
55-
"no-dupe-keys": 2,
56-
"no-duplicate-case": 2,
57-
"no-empty": 2,
58-
"no-empty-character-class": 2,
59-
"no-ex-assign": 2,
60-
"no-extra-boolean-cast": 2,
61-
"no-extra-semi": 2,
62-
"no-func-assign": 2,
63-
"no-inner-declarations": 2,
64-
"no-invalid-regexp": 2,
65-
"no-irregular-whitespace": 2,
66-
"no-mixed-spaces-and-tabs": 2,
67-
"no-multi-spaces": 2,
68-
"no-negated-in-lhs": 2,
69-
"no-obj-calls": 2,
70-
"no-regex-spaces": 2,
71-
"no-spaced-func": 2,
72-
"no-sparse-arrays": 2,
73-
"no-trailing-spaces": 2,
74-
"no-unexpected-multiline": 2,
75-
"no-unreachable": 2,
76-
"no-whitespace-before-property": 2,
77-
"object-curly-spacing": 2,
78-
"quotes": [
79-
2,
80-
"single"
81-
],
82-
"semi": [
83-
2,
84-
"always"
85-
],
86-
"space-before-blocks": [
87-
2,
88-
"always"
89-
],
90-
"space-before-function-paren": [
91-
2,
92-
"always"
93-
],
94-
"space-in-parens": [
95-
2,
96-
"never"
97-
],
98-
"space-infix-ops": 2,
99-
"space-unary-ops": [
100-
2,
101-
{
102-
"nonwords": false,
103-
"words": true
104-
}
105-
],
106-
"spaced-comment": [
107-
2,
108-
"always"
109-
],
110-
"use-isnan": 2,
111-
"valid-jsdoc": 1,
112-
"valid-typeof": 2
11314
}
11415
}

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ services:
77
language: node_js
88
matrix:
99
include:
10-
- node_js: "4.7"
10+
- node_js: "4.8"
1111
env: LINT=0
12-
- node_js: "6.9"
12+
- node_js: "6.10"
1313
env: LINT=0
14-
- node_js: "7.4"
14+
- node_js: "7.10"
1515
env: LINT=1
1616

1717
cache:
@@ -25,7 +25,7 @@ notifications:
2525

2626
script:
2727
- docker run -d --name mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=1 -e MYSQL_DATABASE=test -p 33306:3306 mysql:5.7
28-
- docker run --link mysql:db -e CHECK_PORT=3306 -e CHECK_HOST=db giorgos/takis
28+
- MYSQL_PORT=33306 node tools/wait-up.js
2929
- node --version
3030
- yarn --version
3131
- if [ "$LINT" = "1" ]; then yarn run lint; fi

README.md

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,32 @@ npm install --save mysql2
5353

5454
```js
5555
// get the client
56-
var mysql = require('mysql2');
56+
const mysql = require('mysql2');
5757

5858
// create the connection to database
59-
var connection = mysql.createConnection({host:'localhost', user: 'root', database: 'test'});
59+
const connection = mysql.createConnection({
60+
host: 'localhost',
61+
user: 'root',
62+
database: 'test'
63+
});
6064

6165
// simple query
62-
connection.query('SELECT * FROM `table` WHERE `name` = "Page" AND `age` > 45', function (err, results, fields) {
63-
console.log(results); // results contains rows returned by server
64-
console.log(fields); // fields contains extra meta data about results, if available
65-
});
66+
connection.query(
67+
'SELECT * FROM `table` WHERE `name` = "Page" AND `age` > 45',
68+
function(err, results, fields) {
69+
console.log(results); // results contains rows returned by server
70+
console.log(fields); // fields contains extra meta data about results, if available
71+
}
72+
);
6673

6774
// with placeholder
68-
connection.query('SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Page', 45], function (err, results) {
69-
console.log(results);
70-
});
75+
connection.query(
76+
'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',
77+
['Page', 45],
78+
function(err, results) {
79+
console.log(results);
80+
}
81+
);
7182
```
7283

7384
## Using Prepared Statements
@@ -80,51 +91,59 @@ MySQL provides `execute` helper which will prepare and query the statement. You
8091

8192
```js
8293
// get the client
83-
var mysql = require('mysql2');
94+
const mysql = require('mysql2');
8495

8596
// create the connection to database
86-
var connection = mysql.createConnection({host:'localhost', user: 'root', database: 'test'});
97+
const connection = mysql.createConnection({
98+
host: 'localhost',
99+
user: 'root',
100+
database: 'test'
101+
});
87102

88103
// execute will internally call prepare and query
89-
connection.execute('SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Rick C-137', 53], function (err, results, fields) {
90-
console.log(results); // results contains rows returned by server
91-
console.log(fields); // fields contains extra meta data about results, if available
92-
93-
// If you execute same statement again, it will be picked form a LRU cache
94-
// which will save query preparation time and give better performance
95-
});
104+
connection.execute(
105+
'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',
106+
['Rick C-137', 53],
107+
function(err, results, fields) {
108+
console.log(results); // results contains rows returned by server
109+
console.log(fields); // fields contains extra meta data about results, if available
110+
111+
// If you execute same statement again, it will be picked form a LRU cache
112+
// which will save query preparation time and give better performance
113+
}
114+
);
96115
```
97116
## Using Promise Wrapper
98117

99118
MySQL2 also support Promise API. Which works very well with ES7 async await.
100119

101120
<!--eslint-disable-next-block-->
102121
```js
103-
// get the client
104-
let mysql = require('mysql2/promise');
105-
106-
// create the connection
107-
let connection = await mysql.createConnection({host:'localhost', user: 'root', database: 'test'});
108-
109-
// query database
110-
let [rows, fields] = await connection.execute('SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Morty', 14]);
122+
async function main() {
123+
// get the client
124+
const mysql = require('mysql2/promise');
125+
// create the connection
126+
const connection = await mysql.createConnection({host:'localhost', user: 'root', database: 'test'});
127+
// query database
128+
const [rows, fields] = await connection.execute('SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Morty', 14]);
129+
}
111130
```
112131

113132
MySQL2 use default `Promise` object available in scope. But you can choose which `Promise` implementation you want to use
114133

115134
<!--eslint-disable-next-block-->
116135
```js
117136
// get the client
118-
let mysql = require('mysql2/promise');
137+
const mysql = require('mysql2/promise');
119138

120139
// get the promise implementation, we will use bluebird
121-
let bluebird = require('bluebird');
140+
const bluebird = require('bluebird');
122141

123142
// create the connection, specify bluebird as Promise
124-
let connection = await mysql.createConnection({host:'localhost', user: 'root', database: 'test', Promise: bluebird});
143+
const connection = mysql.createConnection({host:'localhost', user: 'root', database: 'test', Promise: bluebird});
125144

126145
// query database
127-
let [rows, fields] = await connection.execute('SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Morty', 14]);
146+
const [rows, fields] = connection.execute('SELECT * FROM `table` WHERE `name` = ? AND `age` > ?', ['Morty', 14]);
128147
```
129148

130149
## API and Configuration

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ environment:
77
LINT: 0
88

99
matrix:
10-
- nodejs_version: "6.9"
11-
- nodejs_version: "7.3"
10+
- nodejs_version: "6.10"
11+
- nodejs_version: "7.10"
1212
LINT: 1
1313

1414
services:

documentation/Authentication-Switch.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The client respond with opaque blob matching requested plugin via `callback(null
1212
Example: (imaginary `ssh-key-auth` plugin) pseudo code
1313

1414
```js
15-
var conn = mysql.createConnection({
15+
const conn = mysql.createConnection({
1616
user: 'test_user',
1717
password: 'test',
1818
database: 'test_database',
@@ -24,10 +24,10 @@ var conn = mysql.createConnection({
2424
// respond with error to propagate error to connect/changeUser handlers
2525
cb(null, response);
2626
});
27-
} else (
27+
} else {
2828
const err = new Error(`Unknown AuthSwitchRequest plugin name ${pluginName}`);
2929
err.fatal = true;
30-
cb(err)
30+
cb(err);
3131
}
3232
}
3333
});

documentation/Promise-Wrapper.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,53 @@ In addition to errback interface there is thin wrapper to expose Promise-based a
1313
```
1414

1515
```js
16-
/* eslint-env es6 */
17-
var pool = require('mysql2/promise').createPool({}); // or mysql.createPoolPromise({})
18-
pool.getConnection()
19-
.then((conn) => {
20-
var res = conn.query('select foo from bar');
21-
conn.release();
22-
return res;
23-
}).then((result) => {
24-
console.log(result[0][0].foo);
25-
}).catch((err) => {
26-
console.log(err); // any of connection time or query time errors from above
27-
});
28-
16+
const pool = require('mysql2/promise').createPool({}); // or mysql.createPoolPromise({})
17+
pool.getConnection()
18+
.then((conn) => {
19+
const res = conn.query('select foo from bar');
20+
conn.release();
21+
return res;
22+
}).then((result) => {
23+
console.log(result[0][0].foo);
24+
}).catch((err) => {
25+
console.log(err); // any of connection time or query time errors from above
26+
});
2927
```
3028
## ES7 Async Await
31-
<!--eslint-disable-next-block-->
3229
```js
33-
let mysql = require('mysql2/promise');
34-
let conn = await mysql.createConnection({database: test});
30+
/*
31+
async function main () {
32+
const mysql = require('mysql2/promise');
33+
const conn = await mysql.createConnection({ database: test });
3534
let [rows, fields] = await conn.execute('select ?+? as sum', [2, 2]);
35+
}
36+
*/
3637
```
3738

38-
<!--eslint-disable-next-block-->
3939
```js
40+
// eslint-disable-next-block
41+
/*
4042
let mysql = require('mysql2/promise');
4143
let pool = mysql.createPool({database: test});
4244
// execute in parallel, next console.log in 3 seconds
4345
await Promise.all([pool.query('select sleep(2)'), pool.query('select sleep(3)')]);
4446
console.log('3 seconds after');
4547
await pool.end();
4648
await conn.end();
49+
*/
4750
```
4851

4952
## With [CO](https://github.com/tj/co)
5053
<!--eslint-disable-next-block-->
5154
```js
5255
var mysql = require('mysql2');
53-
var co = require('co')
56+
var co = require('co');
5457
co(function * () {
5558
var c = yield mysql.createConnectionPromise({user: 'root', namedPlaceholders: true });
5659
var rows = yield c.query('show databases');
5760
console.log(rows);
58-
console.log( yield c.execute('select 1+:toAdd as qqq', {toAdd: 10}) );
61+
console.log(yield c.execute('select 1+:toAdd as qqq', {toAdd: 10}));
5962
yield c.end();
60-
})
63+
});
6164
```
6265
Examples in [/examples/promise-co-await](https://github.com/sidorares/node-mysql2/tree/master/examples/promise-co-await)

examples/binlog-watcher.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ var binlogStream = mysql.createBinlogStream({
1010
flags: 1 // 1 = "non-blocking mode"
1111
});
1212

13-
binlogStream.pipe(through2.obj(function (obj, enc, next) {
14-
console.log(obj);
15-
next();
16-
}));
13+
binlogStream.pipe(
14+
through2.obj(function(obj, enc, next) {
15+
console.log(obj);
16+
next();
17+
})
18+
);

0 commit comments

Comments
 (0)