Skip to content

Instantly share code, notes, and snippets.

Created August 10, 2010 04:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/516658 to your computer and use it in GitHub Desktop.
Save anonymous/516658 to your computer and use it in GitHub Desktop.
(defn do-prepared-with-generated-keys
"Executes an (optionally parameterized) SQL prepared statement on the
open database connection. Each param-group is a seq of values for all of
the parameters. #THIS MONKEY PATCH INCLUDES METADATA#"
[sql & param-groups]
(with-open [stmt (.prepareStatement (connection) sql)]
(doseq [param-group param-groups]
(doseq [[index value] (map vector (iterate inc 1) param-group)]
(.setObject stmt index value))
(.addBatch stmt))
(transaction
(with-meta
(seq (.executeBatch stmt))
(let [gen-keys (.getGeneratedKeys stmt)]
{:generated-keys (doall (map (comp first vals) (resultset-seq gen-keys)))}
)))
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment