Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @synconset/knex-cleaner with all npm packages installed. Try it out:

var knexCleaner = require("@synconset/knex-cleaner")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@synconset/knex-cleaner v1.2.1

Database cleaner for Knex.js and bookshelf.js


Helper library to clean a PostgreSQL, MySQL or SQLite3 database tables using Knex. Great for integration tests.


npm install knex-cleaner


var knexCleaner = require('knex-cleaner');

var knex = require('knex')({
  client: 'mysql',
  connection: {
    host     : '',
    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'
  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.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free