edbond (owner)

Revisions

  • 917650 edbond Fri Jun 26 08:38:53 -0700 2009
gist: 136563 Download_button fork
public
Public Clone URL: git://gist.github.com/136563.git
Embed All Files: show embed
Text #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
require 'rubygems'
require 'couchrest'
 
db = CouchRest.database!("http://127.0.0.1:5984/loans")
db.recreate!
 
doc1 = db.save_doc({:loan_amount => 40000, :loan_period => 4})
doc2 = db.save_doc({:loan_amount => 20000, :loan_period => 2})
 
doc3 = db.save_doc({:loan_amount => 50000, :loan_period => 9})
 
db.save_doc({
  "_id" => "_design/loans",
  :views => {
    :test => {
      :map => "function(doc) { emit([doc.loan_amount, doc.loan_period], doc) }"
    }
  }
})
 
puts db.view("loans/test", {:startkey => [30000, 5], :endkey => [{},{}]})['rows'].inspect