Fork me on GitHub
#sql
<
2019-11-20
>
jmayaalv14:11:11

what’s the best way to store clojure data structures as jsonb objects on postgres using next.jdbc? i tried extending the SettableParameter protocol but the extension point never gets called.

(extend-protocol p/SettableParameter
  clojure.lang.IPersistentVector
  (set-parameter [v ^PreparedStatement stmt ^long idx]
 ......)
Other extensions do get call

jmayaalv15:11:13

it seems my problem is related to the way honeysql. trying to pass a vector as a parameter to store as jsonb.

jmayaalv15:11:16

just for completion this is what i ended up doing.

(-> (sql/insert-into :my_table)
      (sql/values [{:json_payload (h/call :cast json-string :jsonb)}])
      h/format)

8
noisesmith19:11:37

@jmayaalv this is interesting - where in this call is the clojure data serialized to json? - or is json-string already created as json in a prior step?

jmayaalv19:11:24

json-string is already a json. I had to do it manually.