knex-cleaner
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/knex-cleaner package

1.3.1 • Public • Published

knex-cleaner

CircleCI

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() {
  // your database is now clean
});
 
// You can also use this in BookshelfJS
var bookshelf = require('bookshelf')(knex);
 
knexCleaner.clean(bookshelf.knex).then(function() {
 
});
 
// You can also pass if it deletes the tables with delete instead of truncate
// as well as a list of tables to ignore.
 
var options = {
  mode: 'delete', // Valid options 'truncate', 'delete'
  restartIdentity: true, // Used to tell PostgresSQL to reset the ID counter
  ignoreTables: ['Dont_Del_1', 'Dont_Del_2']
}
 
knexCleaner.clean(knex, options).then(function() {
  // your database is now clean
});

The example above used MySQL but it has been tested on PostgreSQL and SQLite3.

Package Sidebar

Install

npm i knex-cleaner

Weekly Downloads

21,489

Version

1.3.1

License

MIT

Unpacked Size

24.8 kB

Total Files

17

Last publish

Collaborators

  • steven-ferguson