/README.md

https://github.com/carljmosca/backbone-couchdb · Markdown · 102 lines · 78 code · 24 blank · 0 comment · 0 complexity · aab1e421dffaa041a63f5ca0624abea4 MD5 · raw file

  1. backbone-couchdb
  2. ================
  3. This is a Backbone.js connector that overrides Backbone's default
  4. sync-behavior and connects your app to your
  5. [CouchDB](https://github.com/apache/couchdb) so that you can
  6. [RELAX](http://vimeo.com/11852209) and don't need to worry about
  7. (real-time) server-side code.
  8. Demos
  9. -----
  10. * [Real time chat](http://backbone.iriscouch.com/backbone-couchapp/_design/backbone_example/index.html) with support for private messages. (source in `/chat_example`)
  11. * [Real time comments](http://backbone.iriscouch.com/backbone-couchapp/_design/backbone_couchapp_comments/index.html). (source in `/comments_example`)
  12. Changelog
  13. ---------
  14. * 1.1
  15. * Fixed a bug with empty key param
  16. * 1.0
  17. * CoffeeScript rewrite
  18. * Support for custom filter functions
  19. * Chat example (including tests)
  20. * Backbone 5.1 support
  21. * Various bugfixes
  22. * Started versioning ;)
  23. Dependencies (already included in the examples)
  24. ------------
  25. * [Backbone.js](https://github.com/documentcloud/backbone) (>= 0.5.1)
  26. * [Underscore.js](https://github.com/documentcloud/underscore)
  27. * [jquery.couch.js](https://github.com/apache/couchdb/blob/trunk/share/www/script/jquery.couch.js)
  28. * [jQuery](http://www.jquery.com/)
  29. Why a new connector?
  30. --------------------
  31. I developed this connector because I didn't want to write a whole new
  32. server that persists the models that Backbone.js creates. Instead of
  33. writing a server you now only have to write a simple design document
  34. containing one simple view and you're done with server-side code and can
  35. fully concentrate on the Backbone App.
  36. Also I wanted to get real time updates when my models are changed on the
  37. server (e.g. by a second user). The CouchDB _changes feed seemed like a
  38. perfect match for this problem.
  39. Getting Started
  40. ---------------
  41. All Backbone apps should work normally without any changes. Simply
  42. include `backbone-couchdb.js` with its dependencies into your project
  43. and configure the connector with your database infos.
  44. Backbone.couch_connector.config.db_name = "backbone-couchapp";
  45. Backbone.couch_connector.config.ddoc_name = "backbone-couchapp";
  46. Backbone.couch_connector.config.global_changes = false;
  47. As you can see you also need to create a new database in your CouchDB
  48. and a new design document that contains the following view:
  49. function(doc) {
  50. if (doc.collection) {
  51. emit(doc.collection, doc);
  52. }
  53. }
  54. If you set `Backbone.couch_connector.config.global_changes` to true, the
  55. connector will automatically update your models with remote changes in
  56. near real time.
  57. Give your [couchapp](https://github.com/couchapp/couchapp) some backbone
  58. ------------------------------------------------------------------------
  59. An easy way to host single-page apps is to enclose them in a couchapp. I
  60. included a sample couchapp project (`/chat_example`) to show you how to
  61. create couchapps with Backbone and this CouchDB connector. You can also
  62. use it as a bare couchapp directory structure for new projects.
  63. There is an instance of this couchapp running on [iriscouch.com
  64. (demo)](http://backbone.iriscouch.com/backbone-couchapp/_design/backbone_example/index.html)
  65. and I uploaded a file with the [annotated
  66. source](http://janmonschke.github.com/backbone-couchdb/app.html) of the
  67. app. (Created with [docco](https://github.com/jashkenas/docco))
  68. Erica support
  69. -------------
  70. [Erica](http://github.com/benoitc/erica) templates are supported. Simply
  71. link the backbone-couchdb folder to ~/.erica/templates. Then you can
  72. create an application using these templates:
  73. $ erica create template=backbone appid=myappname
  74. Learn more
  75. ----------
  76. To show how backbone-couchdb works under the hood I created an annotated
  77. source file located
  78. [here](http://janmonschke.github.com/backbone-couchdb/backbone-couchdb.html).