Skip to content

samlown/backbone-cradle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backbone Cradle

Extension for Backbone to use Cradle as an interface to a CouchDB database for Model persistence. Intended for server-side use of Backbone, but should work if accessing the database directly.

View creation is not supported as cradle already handles this very gracefully.

This library was originally based on Development Seeds' backbone-couch, but in the end takes quite a different approach.

To ensure compatibility with Ruby's CouchRest Model (also maintained by Sam Lown), ensure the 'type' column, is always set in your models.

Changes

  • 2011-10-31 - 0.1.1
  • Upgraded to Cradle 0.5.7

Installation

npm install backbone-cradle

Usage

// Prepare Backbone and Cradle along with a default database
// called 'documents'
var Backbone = require('backbone'),
    cradle   = require('cradle'),
    db       = new (cradle.Connection)().database('documents')

// Create a new backbone-cradle handler
var Couch = require('backbone-cradle')(cradle, db);

// Create your backbone Models using the new handler
var Document = Couch.Model.extend({
  initialize: function() {
    // always set the type for CouchRest Compatibility
    this.set({type: 'Document'});
  }
});

// Do the same for your collections
var DocumentList = Couch.Collection.extend({
  // Name of view to use is always required!
  viewName: 'Document/all'
});

Run tests

Requires Expresso. Tested with version 0.7.6.

cd backbone-cradle/
npm test

Todos

Add support for dynamic collections with a similar implementation to Jan Monschke's backbone-couchdb library.

About

Backbone.js sync for CouchDB using Cradle

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%