npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

couch-cushion

v0.4.2

Published

An ODM build for working with Couchbase

Downloads

3

Readme

Couch Cushion ODM Build Status Analytics

A Node.js ODM for Couchbase

Installation

npm install --save couch-cushion
npm install --save cushion-adapter-couchbase

Note: The odm itself has recently been decoupled from the Couchbase Node SDK so that the objects you use and create via the odm can be used with more versatility; i.e. using Couch Cushion ODM on the front-end without having to also have the entire Couchbase SDK with it as well.

This lets you use the same models on the front-end as on the backend. :D

Basic Usage

var cushion = require('couch-cushion'),
    adapter = require('cushion-adapter-couchbase');

cushion.install(adapter);
cushion.connect({ /* connection config */ });

var User = cushion.model('User', {
    // Used by the ODM for automatically creating a key
    id: { field: 'id', prefix: 'usr' },
    type: { field: 'constant', value: 'user' },
    username: String,
    name: String,
});

var test = new User();
test.username = 'jDoe24';
test.name = 'John Doe';
test.email = '[email protected]';

cushion.save(test, function(err) {
    if (err) throw err;

    cushion.get(test.id, function(err, obj) {
        if (err) throw err;

        console.log(obj.name); // => 'John Doe'
    });
});

Models and Schemas

Documents in couch-cushion are represented as an instance of a model. Models are defined via a schema. The schema setup is loosely based off of that in mongoose.

Defining a schema and creating a model

Models can be defined with plain objects as their schemas, as demonstrated in the Basic Usage example, however much more robust functionality can be had by defining a full-fledged Schema object instead.

var Cushion = require('couch-cushion'),
    crypto = require('crypto');

// Define the base scheme for a user
var User = new Cushion.Schema({
    id:     { field: 'id', prefix: 'usr' },
    type:   { field: 'constant', value: 'user' },
    created: Date,
    updated: Date,

    email: String,
    firstName: String,
    lastName: String,

    password: String,
});

// Add computed properties
User.compute('fullName', function() {
    return this.firstName + ' ' + this.lastName;
});

// Add methods

User.method('setPassword', function setPassword(pw) {
    this.password = crypto.createHash('md5').update(pw).digest('hex');
});


// If a name isn't supplied, the name of the supplied function will be used
// instead
User.method(function checkPassword(pw) {
    var hash = crypto.createHash('md5').update(pw).digest('hex');
    return hash === this.password;
});


// Name and create a model from the schema we just defined
cushion.model('User', User);

Our model then becomes available wherever we use couch-cushion.

var User = cushion.model('User');

var user = new User();
user.firstName = 'John';
user.lastName = 'Doe';

user.fullName;  // => 'John Doe'

user.setPassword('password');
user.checkPassword('nope');     // => false

Schema Fields

A number of fields are available to be defined in a schema, as well as aliases for more user-informative schemas.

  • id - For generating a unique id for a model
  • bool - For storing boolean values
  • string
  • number
  • date
  • constant - For storing values that aren't meant to be changed
  • enum - For storing a value that can only be one of a set number of choices
  • object - For storing javascript objects. Both arrays and plain objects.
  • model - For storing another couch-cushion model as a child.

All the generic object types are aliased so that a schema can be defined using the type itself, rather than a string. Ex:

schema = { 'followers': Array }
// vs.
schema = { 'followers': 'array' };

Objects, Arrays, and Models

Most values types can be accessed directly from the property of their respective field. Models and objects (also subsequently arrays), because of their complexity cannot have their values accessed directly, instead the value must be accessed via a helper property (_).

var User = cushion.model('User', {
    id: 'id',
    username: String,
    followers: Array,
    options: Object,
});

var user = new User();

// A string value can be accessed directly
user.username = 'jDoe';

// An object field can be set directly, and this is preferable.
user.followers = ['tim','tom','tona'];

// But, other cases require the use of the helper property, `_`.
user.followers._[2] = 'tina';
user.follower._.push('tiffany');

var followersCopy = user.followers._.slice();

// This is also true for object properties.
user.options._.status = 'online';

Testing

If you're developing this project, make sure that you create tests for any new features, and that all of your tests run smoothly before committing.

Tests are ran with gulp, along with linting. Just run:

gulp