Skip to content

Commit 922e6de

Browse files
committed
Allow pool configuration when given connection string
fixes #811 closes #812
1 parent 9298d1b commit 922e6de

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ you spot any mistakes.
77
## HEAD
88

99
* Accept MySQL charset (like `UTF8` or `UTF8MB4`) in `charset` option #808
10+
* Accept pool options in connection string to `mysql.createPool` #811
1011
* Clone connection config for new pool connections
1112
* Default `connectTimeout` to 2 minutes
1213
* Throw on unknown SSL profile name #817

Readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,10 @@ Use pool directly.
240240
```js
241241
var mysql = require('mysql');
242242
var pool = mysql.createPool({
243-
host : 'example.org',
244-
user : 'bob',
245-
password : 'secret'
243+
connectionLimit : 10,
244+
host : 'example.org',
245+
user : 'bob',
246+
password : 'secret'
246247
});
247248

248249
pool.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {

lib/PoolConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ var ConnectionConfig = require('./ConnectionConfig');
33

44
module.exports = PoolConfig;
55
function PoolConfig(options) {
6+
if (typeof options === 'string') {
7+
options = ConnectionConfig.parseUrl(options);
8+
}
9+
610
this.connectionConfig = new ConnectionConfig(options);
711
this.waitForConnections = (options.waitForConnections === undefined)
812
? true

test/unit/test-PoolConfig.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,15 @@ test('PoolConfig#Constructor', {
2929
assert.equal(config.connectionConfig.debug, true);
3030
assert.equal(config.connectionConfig.charsetNumber, Charsets.BIG5_CHINESE_CI);
3131
},
32+
33+
'connection string can configure pool': function() {
34+
var url = 'mysql://myhost:3333/mydb?connectionLimit=2';
35+
var config = new PoolConfig(url);
36+
37+
assert.ok(config.connectionConfig);
38+
assert.equal(config.connectionConfig.host, 'myhost');
39+
assert.equal(config.connectionConfig.port, 3333);
40+
assert.equal(config.connectionConfig.database, 'mydb');
41+
assert.equal(config.connectionLimit, 2);
42+
},
3243
});

0 commit comments

Comments
 (0)