diff --git a/src/com/ashafa/clutch.clj b/src/com/ashafa/clutch.clj index 36f4f6e..8e5527b 100644 --- a/src/com/ashafa/clutch.clj +++ b/src/com/ashafa/clutch.clj @@ -94,6 +94,17 @@ :data {:source (str srcdb) :target (str tgtdb)})) +(defdbop uuids + "Returns a list of n fresh UUID's from the server for use as id in future calls + to put-document. For the rationale behind preferring PUT requests with + pre-generated ids to POST requests when saving new documents, see + http://wiki.apache.org/couchdb/HTTP_Document_API." + [db n] + (couchdb-request :get + (-> + (url/url db "/_uuids") + (assoc :query {:count n})))) + (def ^{:private true} byte-array-class (Class/forName "[B")) (defn- attachment-info diff --git a/test/test_clutch.clj b/test/test_clutch.clj index 413828b..1ff2deb 100644 --- a/test/test_clutch.clj +++ b/test/test_clutch.clj @@ -171,6 +171,10 @@ (put-document (first test-docs) :id "some_id") (failing-request 409 (put-document (first test-docs) :id "some_id"))) +(defdbtest get-two-uuids + (let [resp (uuids 2)] + (is (= 2 (count (:uuids resp)))))) + (defdbtest update-a-document (let [id (:_id (put-document (nth test-docs 3)))] (update-document (get-document id) {:email "test@example.com"})