will-couchrest 0.33 → 0.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/couchrest.rb
CHANGED
|
@@ -28,7 +28,7 @@ require 'couchrest/monkeypatches'
|
|
|
28
28
|
|
|
29
29
|
# = CouchDB, close to the metal
|
|
30
30
|
module CouchRest
|
|
31
|
-
VERSION = '0.33' unless self.const_defined?("VERSION")
|
|
31
|
+
VERSION = '0.33.1' unless self.const_defined?("VERSION")
|
|
32
32
|
|
|
33
33
|
autoload :Server, 'couchrest/core/server'
|
|
34
34
|
autoload :Database, 'couchrest/core/database'
|
|
@@ -59,6 +59,28 @@ module CouchRest
|
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
+
# Load several documents from the database by ids
|
|
63
|
+
# No exceptions will be raised if the document isn't found
|
|
64
|
+
#
|
|
65
|
+
# ==== Returns
|
|
66
|
+
# [Objects]:: if the document was found
|
|
67
|
+
# documents that are not found are nil
|
|
68
|
+
# or
|
|
69
|
+
# Nil:: if there was an error
|
|
70
|
+
#
|
|
71
|
+
# === Parameters
|
|
72
|
+
# ids<Array> of <String, Integer>:: Document IDs
|
|
73
|
+
# db<Database>:: optional option to pass a custom database to use
|
|
74
|
+
def bulk_get(ids, db = database)
|
|
75
|
+
begin
|
|
76
|
+
rows = db.bulk_load(ids)['rows']
|
|
77
|
+
docs = rows.map{ |row| row['doc'] }
|
|
78
|
+
rescue
|
|
79
|
+
nil
|
|
80
|
+
else
|
|
81
|
+
docs.map{|doc| new(doc) if doc }
|
|
82
|
+
end
|
|
83
|
+
end
|
|
62
84
|
# Load a document from the database by id
|
|
63
85
|
# An exception will be raised if the document isn't found
|
|
64
86
|
#
|
|
@@ -226,7 +226,36 @@ describe "ExtendedDocument" do
|
|
|
226
226
|
lambda{foundart = Article.get!('matt aimonetti')}.should raise_error
|
|
227
227
|
end
|
|
228
228
|
end
|
|
229
|
-
|
|
229
|
+
|
|
230
|
+
describe "bulk getting several models" do
|
|
231
|
+
before(:all) do
|
|
232
|
+
@art1 = Article.new(:title => 'All About Getting')
|
|
233
|
+
@art1.save
|
|
234
|
+
|
|
235
|
+
@art2 = Article.new(:title => 'Even More About Getting')
|
|
236
|
+
@art2.save
|
|
237
|
+
|
|
238
|
+
@art3 = Article.new(:title => 'Not Really About Getting')
|
|
239
|
+
@art3.save
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it "should load and instantiate all" do
|
|
243
|
+
foundarts = Article.bulk_get [@art1.id, @art2.id, @art3.id]
|
|
244
|
+
|
|
245
|
+
foundarts[0].title.should == @art1.title
|
|
246
|
+
foundarts[1].title.should == @art2.title
|
|
247
|
+
foundarts[2].title.should == @art3.title
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it "should return nil if `get` is used and the document doesn't exist" do
|
|
251
|
+
foundarts = Article.bulk_get [@art1.id, "bad id", @art3.id]
|
|
252
|
+
|
|
253
|
+
foundarts[0].title.should == @art1.title
|
|
254
|
+
foundarts[1].should be_nil
|
|
255
|
+
foundarts[2].title.should == @art3.title
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
230
259
|
describe "getting a model with a subobjects array" do
|
|
231
260
|
before(:all) do
|
|
232
261
|
course_doc = {
|