honeysql

Shlomit Sibony 2023-06-25T21:28:54.499839Z

Hi all, will appreciate any help with this issue 🙏 https://clojurians.slack.com/archives/C1Q164V29/p1687703215327339

p-himik 2023-06-25T21:49:51.232139Z

What is the code that you currently have?

seancorfield 2023-06-25T21:56:29.728909Z

@shlomit.sibony I'm wondering if HoneySQL's :array syntax will help here, based on the manually constructed insert you showed that worked: https://github.com/seancorfield/honeysql/blob/develop/doc/special-syntax.md#array

seancorfield 2023-06-25T21:56:51.603519Z

(I'd point you at the better-formatted docs but http://cljdoc.org is down right now)

p-himik 2023-06-25T22:05:55.270459Z

Somewhat related - when working with lots of similar values, I prefer to bind them as a single array parameter and not as multiple separate parameters. To do that, I have a few helpers. E.g. when I need to query some items based on their integer IDs, I use this:

(defn ids [coll]
  (into-array Integer/TYPE coll))
Perhaps a similar approach can work here. Probably not with plain arrays but your own custom wrapper type that has special PG<->CLJ conversion defined for it.

Shlomit Sibony 2023-06-26T06:22:16.659299Z

thanks @p-himik, I use the ->pgobject wrapper as written in https://github.com/seancorfield/next-jdbc/blob/8e68c1be61c9aa7d71d0faa373accbe2762e35c8/doc/tips-and-tricks.md#working-with-json-and-jsonb How can I extend it to array of pg objects in prepare/SettableParameter of IPersistentVector using the method you suggested?

Shlomit Sibony 2023-06-26T07:31:15.797119Z

@p-himik that worked!!! I had to change prepare/SettableParameter from:

IPersistentVector
  (set-parameter [v ^PreparedStatement s i]
    (.setObject s i (->pgobject v)))
to
IPersistentVector
  (set-parameter [v ^PreparedStatement s i]
    (.setObject s i (into-array PGobject (mapv ->pgobject v))))
Thank you! 👑

👍 1
seancorfield 2023-06-25T23:05:31.585279Z

Although not mentioned in #releases this also includes the experimental formatf function for folks to play with and provide feedback on.