Closed sbefort closed 8 years ago
Thanks for reporting this, it's not a good thing when the examples don't work :-)
Seems like the mysql driver has changed it's API signature since when this snippet was created.
I quickly hacked it about and
// Create a MySQL connection pool with
// a max of 10 connections, a min of 2, and a 30 second max idle time
var Pool = require('generic-pool').Pool;
var mysql = require('mysql');
var pool = new Pool({
name : 'mysql',
create : function(callback) {
var c = mysql.createConnection({
user: 'scott',
password: 'tiger',
database:'mydb'
})
// parameter order: err, resource
callback(null, c);
},
destroy : function(client) { client.end(); },
max : 10,
// optional. if you set this, make sure to drain() (see step 3)
min : 2,
// specifies how long a resource can stay idle in pool before being removed
idleTimeoutMillis : 30000,
// if true, logs via console.log - can also be a function
log : true
});
should work with the current (2.10.2) mysql version
Happy to accept a PR with this or I'll do it later when I get the time.
also going to link this to #117 as there is a need to improve the docs in general and this a great example of why!
When I attempt the Step 1 example in the docs I get this exception: