Fork me on GitHub
#honeysql
<
2021-07-08
>
mjosefs19:07:29

Hi there! I’m wondering if there’s any way to access a composite type (as in https://www.postgresql.org/docs/current/rowtypes.html#ROWTYPES-ACCESSING ) with honeysql? Re the linked example: as I’m not able to use `:(item).name`, is there any alternative way to express `(item).name`? (I could only find how to compose a composite type in the docs; any way to decompose it would be useful.)

seancorfield21:07:57

I suspect `(keyword "(item)" "name")` would work (but that's pretty ugly). I'd probably define `:.` as special syntax:

``````dev=> (sql/register-fn! :. (fn [_ [x y]] [(str "(" (sql/format-entity x) ")." (sql/format-entity y))]))
...
dev=> (sql/format-expr [:. :item :name])
["(item).name"]``````
Maybe `(sql/format-expr x)` if that can be an expression -- but that returns `[sql & params]` so you'd need a more complex formatted...

👍 4
seancorfield21:07:07

@marcus.josefsson ☝️:skin-tone-2: Does that help?

mjosefs09:07:12

It does - many thanks for the help!