Class | CouchPotato::Database |
In: |
lib/couch_potato/database.rb
|
Parent: | Object |
loads one or more documents by its id(s) behaves like load except it raises a CouchPotato::NotFound if any of the documents could not be found
loads a document by its id(s) id - either a single id or an array of ids returns either a single document or an array of documents (if an array of ids was passed). returns nil if the single document could not be found. when passing an array and some documents could not be found these are omitted from the returned array
saves a document. returns true on success, false on failure. if passed a block will:
saves a document, raises a CouchPotato::Database::ValidationsFailedError on failure
executes a view and return the results. you pass in a view spec which is usually a result of a SomePersistentClass.some_view call.
Example:
class User include CouchPotato::Persistence property :age view :all, key: :age end db = CouchPotato.database db.view(User.all) # => [user1, user2]
You can pass the usual parameters you can pass to a couchdb view to the view:
db.view(User.all(limit: 5, startkey: 2, reduce: false))
For your convenience when passing a hash with only a key parameter you can just pass in the value
db.view(User.all(key: 1)) == db.view(User.all(1))
Instead of passing a startkey and endkey you can pass in a key with a range:
db.view(User.all(key: 1..20)) == db.view(startkey: 1, endkey: 20) == db.view(User.all(1..20))
You can also pass in multiple keys:
db.view(User.all(keys: [1, 2, 3]))