Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

polyclay-couch

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polyclay-couch

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

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

polyclay-couch

A couch persistence adapter for Polyclay.

on npm Tests Coverage Dependencies

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:

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.

Keywords

FAQs

Package last updated on 15 Feb 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc