Skip to content

Commit

Permalink
Make clj-record.util/id-query-for a multimethod.
Browse files Browse the repository at this point in the history
  • Loading branch information
duelinmarkers committed Sep 4, 2009
1 parent 7618c5e commit 99cf067
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/clj_record/util.clj
Expand Up @@ -16,13 +16,13 @@
(some #(.endsWith lc %) ["s" "z" "ch" "sh" "x"]) (str lc "es")
:else (str lc "s"))))

(defn id-query-for [{:keys [subprotocol] :as db-spec} table-name]
(cond
(= subprotocol "derby")
"VALUES IDENTITY_VAL_LOCAL()"
(= subprotocol "postgresql")
(str "SELECT currval(pg_get_serial_sequence('" table-name "','id'))")
(= subprotocol "mysql")
"SELECT LAST_INSERT_ID()"
:else
(throw (Exception. (str "Unrecognized db-spec: " db-spec)))))
(defmulti id-query-for :subprotocol)
(defmethod id-query-for "derby" [_ _]
"VALUES IDENTITY_VAL_LOCAL()")
(defmethod id-query-for "postgresql" [_ table-name]
(str "SELECT currval(pg_get_serial_sequence('" table-name "','id'))"))
(defmethod id-query-for "mysql" [_ _]
"SELECT LAST_INSERT_ID()")
(defmethod id-query-for :default [db-spec _]
(throw (Exception. (str "Unrecognized db-spec subprotocol: " db-spec))))

0 comments on commit 99cf067

Please sign in to comment.