How to change jdbc return types?

Walkable is the only sql library out there that makes use of namespaced keywords so you know exactly which column from which table you are working on. Walkable also leverage Pathom’s plugin architecture so you can write “middleware” for such specific column.

Say you have a table person with columns id, name, yob in it. The type of yob is integer.

[{[:person/by-id 42]
  [:person/id :person/name :person/yob]}]
;; select id, name, yob from person where id = 42
;; => #:person{:id 42 :name "joe" :yob 24}

but your Clojure program doesn’t throw exceptions in production which makes your Java friends think it’s not a “real” one :smiley: So under their pressure you must introduce a bug by telling yob to always return strings( ie #:person{:id 42 :name "joe" :yob "24"}). Here’s how:

(def post-processing
  {::p/wrap-read
   (fn [reader]
     (fn [env]
       (let [k (-> env :ast :dispatch-key)]
         (case k
           :person/yob
           (let [true-yob (reader env)] ;; the original value from database
             (str true-yob))

           ;; default
           (reader env)))))})

(def pathom-parser
  (p/parser
    {::p/plugins
     [(p/env-plugin
        {::p/reader
         [sqb/pull-entities p/map-reader]})
post-processing]}))

You write the “middleware” once and forget about it. Now you can write whatever queries you like, but the results for the specific column are always in desired type.