Load all documents that have the “couchrest-type” field equal to the name of the current class. Take the standard set of CouchRest::Database#view options.
# File lib/couchrest/mixins/document_queries.rb, line 14 def all(opts = {}, &block) view(:all, opts, &block) end
Returns the number of documents that have the “couchrest-type” field equal to the name of the current class. Takes the standard set of CouchRest::Database#view options
# File lib/couchrest/mixins/document_queries.rb, line 21 def count(opts = {}, &block) all({:raw => true, :limit => 0}.merge(opts), &block)['total_rows'] end
Load the first document that have the “couchrest-type” field equal to the name of the current class.
The first object instance available
or
if no instances available
View options, see CouchRest::Database#view options for more
info.
# File lib/couchrest/mixins/document_queries.rb, line 36 def first(opts = {}) first_instance = self.all(opts.merge!(:limit => 1)) first_instance.empty? ? nil : first_instance.first end
Load a document from the database by id No exceptions will be raised if the document isn’t found
if the document was found
or
Document ID
optional option to pass a custom database to use
# File lib/couchrest/mixins/document_queries.rb, line 52 def get(id, db = database) begin get!(id, db) rescue nil end end
Load a document from the database by id An exception will be raised if the document isn’t found
if the document was found
or Exception
Document ID
optional option to pass a custom database to use
# File lib/couchrest/mixins/document_queries.rb, line 72 def get!(id, db = database) doc = db.get id create_from_database(doc) end