# bookshelf-check-duplicates

> Bookshelf plugin that checks if there's a duplicate in a database

Latest version **0.2.2** (published 2015-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install bookshelf-check-duplicates
pnpm add bookshelf-check-duplicates
yarn add bookshelf-check-duplicates
bun add bookshelf-check-duplicates
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2015-09-04 |
| First published | 2015-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jaka Hudoklin |
| Maintainers | gatehub |
| Keywords | bookshelf, check, duplicates |

## Links

- npm: https://www.npmjs.com/package/bookshelf-check-duplicates
- Repository: https://github.com/GateHubNet/bookshelf-check-duplicates
- Issues: https://github.com/GateHubNet/bookshelf-check-duplicates/issues
- npm.io page: https://npm.io/package/bookshelf-check-duplicates

## Dependencies (2)

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

## Recent versions

- 0.2.2 (latest) — 2015-09-04
- 0.2.1 — 2015-09-04
- 0.2.0 — 2015-09-04

## README

# Bookshelf check duplicates

Bookshelf plugin that checks for duplicates in a database.

## Installation

    npm install bookshelf-check-duplicates

Then in your bookshelf configuration:

    var bookshelf = require('bookshelf')(knex);
    bookshelf.plugin(require('bookshelf-check-duplicates');

## Usage

Define bookshelf model with additional attributes


    var User = bookshelf.Model.extend({
      tableName: 'users',
      duplicates: ['name']
    });

    User.forge({name: 'admin'}).save().then(function(admin) {
      User.forge({name: 'user'}).save().catch(function(err) {
        assert(err instanceof bookshelf.Model.DuplicateError);
      });
    });

Whenever model is saved `validateDuplicates` will check if there's already a
saved model with same value of speciffied fields, and if there is
`bookshelf.Model.DuplicateError` error will be thrown.

## License

[MIT](https://opensource.org/licenses/MIT)

## Author

[offlinehacker](https://github.com/offlinehacker)

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