Created
August 10, 2010 04:20
-
-
Save anonymous/516658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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