wheelhouse-couch v0.4.4
wheelhouse-couch
A wheelhouse package for using Backbone server side with flatiron. This sets Couch as the data store for the server and is largely a rewrite of backbone-couch. CouchDB communication is via the excellent cradle CouchDB library.
Usage
var flatiron = require('flatiron')
, app = flatiron.app
, dbPlugin = require('wheelhouse-couch')
app.use(flatiron.plugins.http, {})
app.use(dbPlugin, {
name: 'database-name'
, host: 'localhost' // default
, port: 5984 // default
// also takes cradle options
, cache: false // disabled by default b/c cradle's cache doesn't play nicely if your app is hosted on multiple servers
, raw: false // cradle default
// additional advanced options
, getId: function(model){ // used internally to get the DB id from the model. the default behavior follows: {{collectionName}}/{{UUID}}
return model.url().substring(1) // default
}
, getCollectionName: function(collection){
// you might want to override this if your collection urls don't match your collection names
// e.g. if your collection url is '/api/collectionName', you could use: `return collection.url.split('/')[2]`
return collection.url.substring(1) // default
}
}, function(){} // do something after the database connection has been established
)
app.start(8999)
After using the plugin, Backbone.sync
is overridden to use CouchDB on the server.
app.config.set('db:name', 'database-name')
app.config.set('db:host', 'localhost')
app.config.set('db:cache', true)
// …
Important note:
Your models should override the default id
attribute to use _id
.
var model = Backbone.Model.extend({
idAttribute: '_id'
})
tests
The grunt way
You must have grunt-cli installed: sudo npm i -g grunt-cli
npm test
You'll need to have a user on your db with the username test
and the password test
.
The Mocha way
mocha test/specs -ui bdd
Changelog
0.4.4
security fix it is no longer possible to bypass the delete method by manually setting isDeleted: true
0.4.3
Updated publish process.
0.4.2
Send updatedAt
and createdAt
back out when they're modified.
0.4.1
Publish error
0.4.0
- breaking change (kinda) no longer automatically reading options from
app.config.get('db')
(this never really was operational anyway) - update the
backbone/collection
view to only look at ids with a/
in them… for performance. - Add unit tests
- Updates retry on a document update conflict
- fix error callbacks. They now return just the response … which is as Backbone intended.
- many methods were private before. They're now exposed in
.internals
- changes feed now removes attributes from the model that were deleted in the db
- the delete method is now much smarter… by just re-implementing the update method
- new
createdAt
andupdatedAt
are now automatically created and updated.
0.3.10
- on db update error, don't log the input. It leads to log pollution.
0.3.9
- pass
notOriginal
for changes feed upates. This enables ignoring of events on changes that are triggered on another server.
formerly known as flatiron-couch-backbone
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago