Skip to content

Commit

Permalink
Merge pull request #53 from fragglebob/master
Browse files Browse the repository at this point in the history
Add support for mysql with pooled connection
  • Loading branch information
emerleite committed Nov 15, 2016
2 parents 9026594 + 4c908b0 commit 65aaa63
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/database-cleaner.js
Expand Up @@ -50,9 +50,12 @@ var DatabaseCleaner = module.exports = function(type, config) {
db.query('show tables', function(err, tables) {
if (err) return callback(err);

var database = db.config.connectionConfig ?
db.config.connectionConfig.database : db.config.database;

var count = 0;
var length = tables.length;
var tableName = 'Tables_in_' + db.config.database;
var tableName = 'Tables_in_' + database;
var skippedTables = config.mysql.skipTables;
var strategy = config.mysql.strategy || 'deletion';
if (strategy !== 'deletion' && strategy !== 'truncation') {
Expand Down
16 changes: 16 additions & 0 deletions test/mysql.test.js
Expand Up @@ -9,6 +9,11 @@ var mysql = require('mysql'),
host: process.env.MYSQL_HOST || 'localhost',
user: 'root',
database: 'database_cleaner'
}),
pool = new mysql.createPool({
host: process.env.MYSQL_HOST || 'localhost',
user: 'root',
database: 'database_cleaner'
});

var queryClient = _.curry(function(query, values, next) {
Expand Down Expand Up @@ -125,6 +130,17 @@ describe('mysql', function() {
});
});
});

describe('with pooled connection', function() {
before(function(done) {
databaseCleaner = new DatabaseCleaner('mysql');
done();
});

it('should not error with a pooled connection', function(done) {
databaseCleaner.clean(pool, done);
});
});
});

describe('mysql empty', function() {
Expand Down

0 comments on commit 65aaa63

Please sign in to comment.