Skip to content

Instantly share code, notes, and snippets.

@rcanepa
Forked from avescodes/gist:e5d1acbb007f47655508
Last active February 20, 2016 21:52
Show Gist options
  • Save rcanepa/830e3844c08e143a2ecc to your computer and use it in GitHub Desktop.
Save rcanepa/830e3844c08e143a2ecc to your computer and use it in GitHub Desktop.
Great little snippet for using Postgres enum types inside clojure.java.jdbc
(defn str->pg-enum
"Convert a string value into an enum-compatible object."
[enum-type s]
(doto (org.postgresql.util.PGobject.)
(.setType enum-type)
(.setValue s)))
(def str->status
"Convert a string status into a something_status enum object"
(partial string->pg-enum "something_status"))
;; Use it:
(str->status :accepted)
; -> #<PGobject accepted>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment