# knex-cleaner

> Database cleaner for Knex.js and bookshelf.js

Latest version **1.3.1** (published 2020-08-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install knex-cleaner
pnpm add knex-cleaner
yarn add knex-cleaner
bun add knex-cleaner
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2020-08-20 |
| First published | 2015-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/knex-cleaner) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 24.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 79 |
| Author | Steven Ferguson |
| Maintainers | steven-ferguson |
| Keywords | knex, knexjs, bookshelf, bookselfjs |

## Links

- npm: https://www.npmjs.com/package/knex-cleaner
- Repository: https://github.com/steven-ferguson/knex-cleaner
- Homepage: https://github.com/steven-ferguson/knex-cleaner#readme
- Issues: https://github.com/steven-ferguson/knex-cleaner/issues
- npm.io page: https://npm.io/package/knex-cleaner

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.13
- [bluebird](https://npm.io/package/bluebird.md) ^2.9.13

## Recent versions

- 1.3.1 (latest) — 2020-08-20
- 1.3.0 — 2019-08-13
- 1.2.1 — 2019-07-11
- 1.2.0 — 2019-07-11
- 1.1.4 — 2017-12-24
- 1.1.3 — 2016-03-28
- 1.1.2 — 2016-03-28
- 1.1.1 — 2015-04-14
- 1.1.0 — 2015-04-11
- 1.0.0 — 2015-03-15
- 0.0.1 — 2015-03-10

## README

# knex-cleaner
[![CircleCI](https://circleci.com/gh/steven-ferguson/knex-cleaner.svg?style=svg)](https://circleci.com/gh/steven-ferguson/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
```javascript
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.

---
_Source: https://npm.io/package/knex-cleaner · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
