On Mar 8, 2009, at 1:53 PM, Rich Hickey wrote:

First up is contrib.sql, where insert-rows and insert-values both take
a vector of column names followed by vectors of unlabeled values that
must be in the same order as the corresponding columns. I would hope
never to have such fragile things as those vectors in my programs.

For large data sets with a regular structure, insert-rows and insert- values use the jdbc interface very efficiently. They are also convenient building blocks for other functions to use.

OTOH, the query and update APIs take and return maps.

clojure.contrib.sql now includes:

(defn insert-records
  "Inserts records into a table. records are maps from strings or
  keywords (identifying columns) to values."
  [table & records]
  (doseq [record records]
    (insert-values table (keys record) (vals record))))

Here's an example from clojure.contrib.sql.test:

(defn insert-records-fruit
  "Insert records, maps from keys specifying columns to values"
  []
  (sql/insert-records
   :fruit
   {:name "Pomegranate" :appearance "fresh" :cost 585}
   {:name "Kiwifruit" :grade 93}))

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to