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 🙏

© 2024 – Pkg Stats / Ryan Hefner

backbone-couch

v2.0.1

Published

Backbone.js sync for CouchDB

Downloads

28

Readme

Backbone Couch

Overrides for Backbone to use CouchDB for Model persistence. Intended for server-side use of Backbone like in Bones.

Installation

npm install backbone-couch

Usage

var Backbone = require('backbone');

// Create a new backbone-couch handler for a database 'documents'.
var couch = require('backbone-couch')({
    host: '127.0.0.1',
    port: '5984',
    name: 'documents'
});

// Create database, push default design documents to it and
// assign sync method to Backbone.
couch.install(function(err) {
    Backbone.sync = couch.sync;
});

// Backbone.sync will now load and save models from a 'documents' couch db.

Conventions

backbone-couch stores models in using the model.url as its _id. By default, Collections retrieve models by matching the Collection url against the initial portion of the Model url. See backbone.json for the default design document and collection view.

var orange = new FruitModel({id: 'orange'});
var apple = new FruitModel({id: 'apple'});
var banana = new FruitModel({id: 'banana'});

console.log(orange.url()); // fruits/orange
console.log(apple.url());  // fruits/apple
console.log(banana.url()); // fruits/banana

var fruits = new FruitCollection();

console.log(fruits.url);   // fruits

fruits.fetch();            // retrieves orange, apple, banana

To override the default design doc with your own special sauce use the doc option when calling couch.install().

// Pass a filepath to your design doc.
couch.install({doc: '/path/to/my/doc.json'}, callback);

// Or provide a literal js object directly.
couch.install({doc: {
    _id: '_design/backbone',
    language: 'javascript'
}, callback);

Your design doc should use _design/backbone as its _id. Collections will be called against this design doc using their url. For example, if you have a Collection /blog/recent, your design doc should provide a rewrite rule to respond to this path:

{
    "_id":"_design/backbone",
    "language":"javascript",
    "views": {
        "recent": {
            "map": "function(doc) { emit(doc._id, doc._id) }"
        }
    },
    "rewrites": [
        {
            "from": "/blog/recent",
            "to": "_view/recent",
            "query": {
                "limit": "10"
                "include_docs": "true"
            }
        }
    ]
}

See the rewrite handler docs or this blog post for more info on design doc rewrites.

Run tests

You must configure CouchDB to work with HTTPS in order to run tests. See this wiki page

cd backbone-couch/
npm test