luminus 2020-07-09

Not with luminus and whatever sql client it uses. But clojure.java.jdbc I define these two functions:

(defn- to-pg-json [content]
  (doto (PGobject.)
    (.setType (name :jsonb))
    (.setValue (json/write-str content))))

(defn read-json-b
  [^PGobject x]
  (when-let [val (.getValue x)]
    (json/read-str val)))
and then call it like this:
(j/insert! db :api_data {:users_id users-id :spec_id spec-id :component_path component-path
                         :content  (to-pg-json content)})

And a query that uses postgres 12 functions looks like this:

(str "select jsonb_path_query_array(content, '$[*] ? (@.id == " id ")') as content from api_data
               where users_id = ? and spec_id = ? and component_path = ? and content @> '[{\"id\":" id "}]'")

Unfortunately I did not figure out yet how to do parameterized select with psql json queries.