TODO: Write a gem description
Add this line to your application's Gemfile:
gem 'dolly'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dolly
Add config/couchdb.yml
sample file:
defaults: &defaults
host: localhost
port: 5984
protocol: http
design: 'test'
development:
<<: *defaults
name: dolly
test:
<<: *defaults
name: dolly_test
production:
<<: *defaults
name: dolly_production
The database on config/couchdb.yml will be added with the task:
rake db:setup
Since 0.6 Dolly will not require couch-view for find, all, first and last methods.
You can save your custom views as coffescript files inside db/designs/*.map.coffee
And push them into the default design document with:
rake db:design
This will not replace de default find view.
####Document Model
class User < Dolly::Document
database_name 'db'
set_design_doc 'dolly' #defaults to 'dolly'
property :name, :surname, :address
property :date_of_birth, class_name: Date, default: Date.today
end
User.all #Dolly::Collection #<#User...>, <#User...>
user = User.find "a1b2d3e" #<#User...>
user.name
#Return a User object based on the custom view.
user = User.view 'view_name', {key: ["a", "b", "c"], reduce: true}
# Save doc
user.email = 'foo'
user.save #user.save! exists but doesn do anything yet.
#New Doc
user = User.new
user.name = 'A'
user.save
user = User.new name: 'A'
user.save
user = User.create name: 'A'
#Quering available
User.all
User.first
User.last
# Bulk save
#Bulk saving works adding docs to the bulk_document property.
Dolly::Document.bulk_document << User.new name: 'foo'
# bulk_document includes :[], :<<, :first, :last, :to_a, :count
# it is forwarding to Set, so this will avoid duplicated documents.
# You can add as many documents as you want.
# To trigger the remote save you have to call.
Dolly::Document.bulk_save
- Generators for creating views for attributes search on models.
- Validations?
- Dirty Tracking?
Add to do's
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request