korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.48k stars 222 forks source link

[enhancement] Updating a row should respect `jdbc/ISQLParameter` and `jdbc/ISQLValue` protocols #385

Open pqnelson opened 6 years ago

pqnelson commented 6 years ago

So, I can specify how jdbc should transform a clojure value into a sql value using the ISQLValue and ISQLParameter protocols. If I try this and use korma, inserting values works fine...but updating ignores these protocols, for whatever reason.

For example, a minimal (almost)-working example:

;; store UUIDs as strings
(extend-protocol jdbc/ISQLValue
  java.util.UUID
  (sql-value [uuid]
    (str uuid)))

(defn new-uuid [] (java.util.UUID/randomUUID))

;; dangerous, but just to illustrate my point
;; throws an error, cannot set varchar to type uuid
(korma/update my-table (korma/set-fields {:my-id (new-uuid)}))

;; ...but this works exactly as expected
(korma/insert my-table (korma/values {:my-id (new-uuid)}))