Socket
Socket
Sign inDemoInstall

knex-cleaner

Package Overview
Dependencies
2
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    knex-cleaner

Database cleaner for Knex.js and bookshelf.js


Version published
Weekly downloads
21K
decreased by-21.68%
Maintainers
1
Install size
1.79 MB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 20 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc