# pouchdb-ensure

> Creates a doc or updates it, but only when necessary.

Latest version **1.0.0** (published 2016-07-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install pouchdb-ensure
pnpm add pouchdb-ensure
yarn add pouchdb-ensure
bun add pouchdb-ensure
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-07-21 |
| First published | 2016-07-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Giovanni T. Parra |
| Maintainers | fiatjaf |
| Keywords | pouchdb, pouchdb-plugin, ensure, sure, save, put, ddoc, design, doc |

## Links

- npm: https://www.npmjs.com/package/pouchdb-ensure
- Repository: https://github.com/fiatjaf/pouchdb-ensure
- Homepage: https://github.com/fiatjaf/pouchdb-ensure#readme
- Issues: https://github.com/fiatjaf/pouchdb-ensure/issues
- npm.io page: https://npm.io/package/pouchdb-ensure

## Dependencies (1)

- [deep-equal](https://npm.io/package/deep-equal.md) *

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-07-21

## README

pouchdb-ensure
======

A PouchDB plugin.

Creates a doc or updates it, but only when necessary.

Good to make sure a design doc is saved on the database at startup time, and that it is updated on the database whenever it is changed on the code.

### Usage

```bash
npm install --save pouchdb-ensure
```

```js
PouchDB.plugin(require('pouchdb-ensure'))

var db = new PouchDB('mydb')

db.ensure({
  _id: 'a doc',
  value: 'a value'
})
  .then(doc => {
    // doc is saved and returned
    // doc === {_id: 'a doc', value: 'a value', _rev: '1-...'}

    return db.ensure({_id: 'a doc', value: 'a value'})
  })
  .then(doc => {
    // doc is just returned, not saved again
    // doc === {_id: 'a doc', value: 'a value', _rev: '1-...'}

    return db.ensure({_id: 'a doc', value: 'other value'})
  })
  .then(doc => {
    // doc is updated, now _rev is 2-... and value is 'other value'
  })
```

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