Repository is archived
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
Extends couchrest document and adds simple views and document management.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3.0
~> 0.4

Runtime

~> 1.1.3
~> 4.0.0
 Project Readme

CouchRestAdapter¶ ↑

This is a realy early version.

This project rocks and uses MIT-LICENSE.

Requirements¶ ↑

  • Rails > 4

  • Couchrest

  • Requires config/database.yml file

Instalation¶ ↑

Right now there will be a conflict if you use it as it is mixed with ActoveRecord, so you should create your reails project without AR, as in rails new my_app -O

In Gemfile¶ ↑

gem 'couch_rest_adapter'

Sample config/couchdb.yml¶ ↑

All this are required attributes.

defaults: &defaults
  host: localhost
  port: 5984
  protocol: http
  design_doc: my_app
  # optional
  # username: username
  # password: password

development:
  <<: *defaults
  name: db

test:
  <<: *defaults
  name: db_test

Versions > 0.8.0 support https protocol, s

CouchViews¶ ↑

After installing the gem you should run “‘rake db:push:config“` this will setup a design document called as the database.yml “`design_doc“` value with the next structure:

{
   "_id": "_design/my_app",
   "language": "coffeescript",
   "views": {
       "all": {
           "map": "(d) ->\n  split_id = d._id.split('/')\n  t = split_id[0]\n  emit t, d\n",
           "reduce": "# This is only for demosntration one can use the built in count\n(keys, values, rereduce)->\n  if rereduce\n    sum(values)\n  else\n    values.length\n"
       },
       "by_attribute": {
           "map": "(doc) ->\n  type = doc._id.split('/')[0]\n  for a of doc\n    emit([type, a, doc[a]], doc._id)\n"
       },
       "by_type": {
           "map": "(d)->\n  emit d.type.toLowerCase(), d._id if d.type\n"
       },
   }
}

You can add more views as needed into “‘db/designs/“` folder.

This is how the designs are delcared:

db
  designs
    my_map_name.map.coffee
    my_filter_name.filter.coffee
    my_reduce_name.reduce.coffee

Then if you run “‘rake db:push:design“` the “`_design/my_app“ document will be updated. The views need to be written on coffeescript code.

One thing: this will allow you to add tests to your couch views ;-)

Model Declaration¶ ↑

class User < CouchRestAdpater::Base
  use_default_database
end

TODO¶ ↑

  • Allow setting new attributes with “‘model.attribute = value“`

  • More test coverage

  • Add tasks for pushing design documents