knex-cleaner
Helper library to clean a PostgreSQL, MySQL or SQLite3 database tables using Knex. Great for integration tests.
Installation
npm install knex-cleaner
Usage
var knexCleaner = require('knex-cleaner');
var knex = require('knex')({
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}
});
knexCleaner.clean(knex).then(function() {
});
var bookshelf = require('bookshelf')(knex);
knexCleaner.clean(bookshelf.knex).then(function() {
});
var options = {
mode: 'delete',
restartIdentity: true,
ignoreTables: ['Dont_Del_1', 'Dont_Del_2']
}
knexCleaner.clean(knex, options).then(function() {
});
The example above used MySQL but it has been tested on PostgreSQL and SQLite3.