You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

database-cleaner

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

database-cleaner - npm Package Compare versions

Comparing version

to
0.11.0

6

Changelog.md

@@ -0,1 +1,7 @@

0.11.0 / 2016-01-13
==================
* Allow to pass the config data on initialize (gabceb)
* Fix: mysql/postgesql stuck if no table to clean. (Amoki)
0.10.1 / 2015-10-09

@@ -2,0 +8,0 @@ ==================

25

lib/database-cleaner.js

@@ -1,7 +0,10 @@

var DatabaseCleaner = module.exports = function(type) {
var DatabaseCleaner = module.exports = function(type, config) {
var cleaner = {};
try {
var config = require("../../../config/cleaner-config.js");
} catch(e) {
var config = require("../config/cleaner-config.js");
if (!config) {
try {
config = require("../../../config/cleaner-config.js");
} catch(e) {
config = require("../config/cleaner-config.js");
}
}

@@ -45,8 +48,16 @@

if(length === 0) {
// The database is empty
return callback.apply();
}
tables.forEach(function(table) {
if (skippedTables.indexOf(table[tableName]) === -1) {
db.query("DELETE FROM " + table[tableName], function() {
if(err) {
return callback(err);
}
count++;
if (count >= length) {
callback.apply();
callbackCalled = true;
}

@@ -70,2 +81,6 @@ });

if(length === 0) {
// The database is empty
return callback.apply();
}
tables.rows.forEach(function(table) {

@@ -72,0 +87,0 @@ if (skippedTables.indexOf(table['table_name']) === -1) {

2

package.json

@@ -5,3 +5,3 @@ {

"keywords" : [ "database", "cleaner", "mongodb", "redis", "couchdb", "tests", "package.json" ],
"version" : "0.10.1",
"version" : "0.11.0",
"author" : "Emerson Macedo <emerleite@gmail.com>",

@@ -8,0 +8,0 @@ "repository" : {

@@ -16,3 +16,3 @@ var should = require('should'),

if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) {
throw err;
throw err;
}

@@ -39,3 +39,3 @@ });

done();
})
});
});

@@ -66,1 +66,16 @@ });

});
describe('mysql empty', function() {
beforeEach(function(done) {
client.query('CREATE DATABASE database_cleaner', function(err) {
if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) {
throw err;
}
done();
});
});
it('should not stuck if database is empty', function(done) {
databaseCleaner.clean(client, done);
});
});

@@ -117,1 +117,33 @@ var should = require('should'),

});
describe('pg empty', function() {
beforeEach(function(done) {
_done = done;
pg.connect(connectionString, function(err, client, done) {
if (err) {
return console.error('could not connect to postgresql', err);
}
client.query('CREATE DATABASE database_cleaner', function(err) {
if (err && err.code != '42P04') {
throw err;
}
done();
_done();
});
});
});
it('should not struck if db is empty', function(done) {
_done = done;
pg.connect(connectionString, function(err, client, done) {
databaseCleaner.clean(client, function() {
done();
_done();
});
});
});
});

Sorry, the diff of this file is not supported yet