Created
November 23, 2015 14:38
-
-
Save lukaszkorecki/c719188a0a35e1855d6b to your computer and use it in GitHub Desktop.
Add JSONB support to yesql and automatically unserialize json/jsonb columns with cheshire
This file contains hidden or 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
| (ns foo.bar | |
| (:require [cheshire.core :as json] | |
| [clojure.java.jdbc :as jdbc]) | |
| (:import [org.postgresql.util PGobject])) | |
| (defn extend-db-driver [] | |
| (extend-type org.postgresql.util.PGobject | |
| jdbc/IResultSetReadColumn | |
| (result-set-read-column [val rsmeta idx] | |
| (let [colType (.getColumnTypeName rsmeta idx)] | |
| (if (or (= colType "json") | |
| (= colType "jsonb")) | |
| (json/parse-string (.getValue val) true) val))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment