# polyclay-couch

> couch persistence adapter for polyclay, the schema-enforcing document mapper

Latest version **0.1.1** (published 2015-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install polyclay-couch
pnpm add polyclay-couch
yarn add polyclay-couch
bun add polyclay-couch
```

## 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.1.1 |
| Published | 2015-02-15 |
| First published | 2013-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | C J Silverio |
| Maintainers | ceejbot |
| Keywords | odm, model, mapper, schema, couchdb, couch, polyclay |

## Links

- npm: https://www.npmjs.com/package/polyclay-couch
- Repository: https://github.com/ceejbot/polyclay-couch
- Issues: https://github.com/ceejbot/polyclay-couch/issues
- npm.io page: https://npm.io/package/polyclay-couch

## Dependencies (3)

- [async](https://npm.io/package/async.md) ~0.9.0
- [cradle](https://npm.io/package/cradle.md) ~0.6.9
- [lodash](https://npm.io/package/lodash.md) ~3.2.0

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2015-02-15
- 0.1.0 — 2015-01-18
- 0.0.1 — 2013-06-05

## README

polyclay-couch
==============

A couch persistence adapter for [Polyclay](https://github.com/ceejbot/polyclay).

[![on npm](http://img.shields.io/npm/v/numbat-emitter.svg?style=flat)](https://www.npmjs.org/package/polyclay-couch)  [![Tests](http://img.shields.io/travis/ceejbot/polyclay-couch.svg?style=flat)](http://travis-ci.org/ceejbot/polyclay-couch) ![Coverage](http://img.shields.io/badge/coverage-99%25-green.svg?style=flat) [![Dependencies](http://img.shields.io/david/ceejbot/polyclay-couch.svg?style=flat)](https://david-dm.org/ceejbot/polyclay-couch)

## How-to

See the polyclay docs for information about how to use the models.

Once you've built a polyclay model, you can mix persistence methods into it:

````javascript
polyclay.persist(ModelFunction, '_id');
polyclay.persist(RedisModelFunc, 'name');
```

You can then set up its access to CouchDB by giving it an existing Cradle connection object plus the name of the database where this model should store its objects. The couch adapter wants two fields in its options hash: a cradle connection and a database name. For instance:

```javascript
var adapterOptions =
{
    connection: new cradle.Connection(),
    dbname: 'widgets'
};
ModelFunction.setStorage(adapterOptions, polyclay.CouchAdapter);
```

If you do not pass a dbname, the adapter will fall back to using the model's `plural`. This is often the expected name for a database.

Every model instance has a pointer to the adapter on its `adapter` field. The adapter in turn gives you access to the cradle connection on `obj.adapter.connection` and the database on `obj.adapter.db`.

### Defining views

You can define views to be added to your couch databases when they are created.  Add a `design` field to your constructor function directly.

Let's add some simple views to the Widget model we created above, one to fetch widgets by owner and one to fetch them by name.

```javascript
Widget.design =
{
    views:
    {
        by_owner: { map: "function(doc) {\n  emit(doc.owner_id, doc);\n}", language: "javascript" },
        by_name: { map: "function(doc) {\n  emit(doc.name, doc);\n}", language: "javascript" }
    }
};
```

Call `Widget.provision()` to create the 'widgets' database in your CouchDB instance. It will have a design document named "_design/widgets" with the two views above defined. The provision method nothing for Redis- or LevelUP-backed models.

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