document view queries
This commit is contained in:
parent
ba16fb586a
commit
75bbb26c7a
1 changed files with 23 additions and 4 deletions
|
@ -5,18 +5,18 @@ require 'digest/md5'
|
||||||
# = CouchRest::Model - ORM, the CouchDB way
|
# = CouchRest::Model - ORM, the CouchDB way
|
||||||
module CouchRest
|
module CouchRest
|
||||||
# = CouchRest::Model - ORM, the CouchDB way
|
# = CouchRest::Model - ORM, the CouchDB way
|
||||||
#
|
#
|
||||||
# CouchRest::Model provides an ORM-like interface for CouchDB documents. It
|
# CouchRest::Model provides an ORM-like interface for CouchDB documents. It
|
||||||
# avoids all usage of <tt>method_missing</tt>, and tries to strike a balance
|
# avoids all usage of <tt>method_missing</tt>, and tries to strike a balance
|
||||||
# between usability and magic. See CouchRest::Model#view_by for
|
# between usability and magic. See CouchRest::Model#view_by for
|
||||||
# documentation about the view-generation system.
|
# documentation about the view-generation system.
|
||||||
#
|
#
|
||||||
# ==== Example
|
# ==== Example
|
||||||
#
|
#
|
||||||
# This is an example class using CouchRest::Model. It is taken from the
|
# This is an example class using CouchRest::Model. It is taken from the
|
||||||
# spec/couchrest/core/model_spec.rb file, which may be even more up to date
|
# spec/couchrest/core/model_spec.rb file, which may be even more up to date
|
||||||
# than this example.
|
# than this example.
|
||||||
#
|
#
|
||||||
# class Article < CouchRest::Model
|
# class Article < CouchRest::Model
|
||||||
# use_database CouchRest.database!('http://localhost:5984/couchrest-model-test')
|
# use_database CouchRest.database!('http://localhost:5984/couchrest-model-test')
|
||||||
# unique_id :slug
|
# unique_id :slug
|
||||||
|
@ -49,6 +49,25 @@ module CouchRest
|
||||||
# self['slug'] = title.downcase.gsub(/[^a-z0-9]/,'-').squeeze('-').gsub(/^\-|\-$/,'')
|
# self['slug'] = title.downcase.gsub(/[^a-z0-9]/,'-').squeeze('-').gsub(/^\-|\-$/,'')
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
#
|
||||||
|
# ==== Examples of finding articles with these views:
|
||||||
|
#
|
||||||
|
# * All the articles by Barney published in the last 24 hours. Note that we
|
||||||
|
# use <tt>{}</tt> as a special value that sorts after all strings,
|
||||||
|
# numbers, and arrays.
|
||||||
|
#
|
||||||
|
# Article.by_user_id_and_date :startkey => ["barney", Time.now - 24 * 3600], :endkey => ["barney", {}]
|
||||||
|
#
|
||||||
|
# * The most recent 20 articles. Remember that the <tt>view_by :date</tt>
|
||||||
|
# has the default option <tt>:descending => true</tt>.
|
||||||
|
#
|
||||||
|
# Article.by_date :count => 20
|
||||||
|
#
|
||||||
|
# * The raw CouchDB view reduce result for the custom <tt>:tags</tt> view.
|
||||||
|
# In this case we'll get a count of the number of articles tagged "ruby".
|
||||||
|
#
|
||||||
|
# Article.by_tags :key => "ruby", :reduce => true
|
||||||
|
#
|
||||||
class Model < Hash
|
class Model < Hash
|
||||||
|
|
||||||
# instantiates the hash by converting all the keys to strings.
|
# instantiates the hash by converting all the keys to strings.
|
||||||
|
|
Loading…
Add table
Reference in a new issue