 
 ;;;; API - batch ops
 
-(defn- keys-and-attrs [{:keys [key vals attrs consistent?] :as request}]
-  (doto (KeysAndAttributes.)
-    (.setKeys (for [v vals] {(name key) (clj-val->db-val v)}))
-    (.setAttributesToGet (when attrs (mapv name attrs)))
-    (.setConsistentRead  consistent?)))
-
-(defn- batch-request-items [requests]
-  (into {} (for [[table request] requests]
-             [(name table) (keys-and-attrs request)])))
-
-;;;; TODO Continue code walk-through below
-
 (defn batch-get-item
-  "Retrieve a batch of items in a single request. DynamoDB limits
-   apply - 100 items and 1MB total size limit. Requested items
-   which were elided by Amazon are available in the returned map
-   key :unprocessed-keys.
-
-  Example:
-  (batch-get-item cred
-    {:users {:key-name :names
-             :keys [\"alice\" \"bob\"]}
-     :posts {:key-name :id
-             :keys [1 2 3]
+  "Retrieves a batch of items in a single request.
+  Limits apply, Ref. http://goo.gl/Bj9TC.
+
+  (batch-get-item creds
+    {:users {:key  :names
+             :vals [\"alice\" \"bob\"]}
+     :posts {:key   :id
+             :vals  [1 2 3]
              :attrs [:timestamp :subject]
              :consistent? true}})"
   [creds requests]


;;;; TODO
;; * Finish up code walk-through.
;; * Go through Rotary PRs, non-PR forks.
;; * README docs.
;; * Benchmarks.
;; * Further tests.
;; * Parallel scans.
;; * Async API.
;; * Auto throughput adjusting.

;;;; API - exceptions


      (doto (BatchGetItemRequest.)
        (.setRequestItems (batch-request-items requests))))))

(defn- put-request    [i] (doto (PutRequest.)    (.setItem (clj-item->db-item i))))
(defn- delete-request [i] (doto (DeleteRequest.) (.setKey  (clj-item->db-item i))))
(defn- write-request  [action item]
  (case action
    :delete (doto (WriteRequest.) (.setDeleteRequest (delete-request item)))
    :put    (doto (WriteRequest.) (.setPutRequest    (put-request    item)))))

(defn batch-write-item
  "Executes a batch of Puts and/or Deletes in a single request.
   Limits apply, Ref. http://goo.gl/Bj9TC. No transaction guarantees are
   provided, nor conditional puts.

   (batch-write-item creds
     [:put    :users {:user-id 1 :username \"sally\"}]
     [:put    :users {:user-id 2 :username \"jane\"}]
     [:delete :users {:user-id 3}])"
  [creds & requests]
  (as-map
    (.batchWriteItem (db-client creds)
