Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
polyclay-couch
Advanced tools
couch persistence adapter for polyclay, the schema-enforcing document mapper
A couch persistence adapter for Polyclay.
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.
FAQs
couch persistence adapter for polyclay, the schema-enforcing document mapper
We found that polyclay-couch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.