summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsdelano <stephen@opscode.com>2011-04-25 14:31:07 -0700
committersdelano <stephen@opscode.com>2011-04-25 14:31:07 -0700
commit8abc9d70a85a3e48fc2b4f507b6331c4cb70769c (patch)
tree1df7e00c68e1cbb5abe867d634b88aac305c604f
parent4648d2d0d6a5037239f74d5d68ce1f6285e1a9c5 (diff)
downloadchef-8abc9d70a85a3e48fc2b4f507b6331c4cb70769c.tar.gz
couchdb:
* enable bulk create of objects * enable bulk view execution
-rw-r--r--chef/lib/chef/couchdb.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/chef/lib/chef/couchdb.rb b/chef/lib/chef/couchdb.rb
index 71ee196462..ba5bd5ad38 100644
--- a/chef/lib/chef/couchdb.rb
+++ b/chef/lib/chef/couchdb.rb
@@ -225,11 +225,30 @@ class Chef
@rest.get_rest(view_string)
end
+ def bulk_view(design, view, keys, options={})
+ view_string = view_uri(design, view)
+ view_string << "?" if options.length != 0
+ view_string << options.map { |k,v| "#{k}=#{URI.escape(v.to_json)}"}.join('&')
+ @rest.post_rest(view_string, { "keys" => keys })
+ end
+
def bulk_get(*to_fetch)
response = @rest.post_rest("#{couchdb_database}/_all_docs?include_docs=true", { "keys" => to_fetch.flatten })
response["rows"].collect { |r| r["doc"] }
end
+ # bulk create a series of objects.
+ # this method is RAW. it does not validate.
+ # it does not index. it does not hold your hand.
+ def bulk_create(objects)
+ objects = Array.new(objects)
+ objects.each do |obj|
+ uuid = UUIDTools::UUID.random_create.to_s
+ obj.couchdb_id = uuid
+ end
+ @rest.post_rest("#{couchdb_database}/_bulk_docs", { "docs" => objects })
+ end
+
def view_uri(design, view)
"#{couchdb_database}/_design/#{design}/_view/#{view}"
end