Any tips on how to express:
SELECT ARRAY[1,2] && foo;
in honeysql (still on v1 in our production app)? The left array is from values from input, the other array foo
is from a tableI guess I can use (h/format (honeysql.types/array [1 2 3]))
and now the [:&& included-uuids :tzdb.tag_uuids]
part: can I generate the &&
as an operator instead of a function?
(sorry, this is probblay in the docs somewhere, but I have trouble finding it š )
Is there some hook to register a thing as an infix thing?
I did this:
(defmethod hf/fn-handler "&&" [op & args]
(let [args (map hf/to-sql args)]
(hf/paren-wrap (str/join (str " " op " ") args))))
Sounds like youāve solved the problem? Which DB is that for? ||
is a variadic infix operator in V2 for string concatenation so Iām a bit surprised to see &&
ā what does it mean?
@seancorfield this is an array operator in postgresql.
array[1,2,3] && array[1,2,3,4]
means all the left elements must occur in the right elementsperhaps allowing people to say: "this is an infix operator" would be easier
Thatās easy in HoneySQL v2 but I think fn-handler
is the right approach in v1.
In v2 itās (sql/register-op! :&& :variadic true)
and youāre off to the races. But Iāll go ahead and add &&
as a built-in for the next v2 version anyway.
Excellent! I'll try to migrate this one namespace to v2 now
We can use them side by side anyway
Yup. develop has that change. Itāll be in RC 3 or āgoldā, whichever comes next.
if I have an array like ARRAY["..."]
but I want to generate ARRAY["..."]::uuid[]
, what's the best option?
[:cast included-uuids :uuid[]]
doesn't work obviously :)hacky and ugly, but it works:
[:&& [:cast included-uuids [:lift (symbol "uuid[]")]] :tzdb.tag_uuids]
open to improvements :)this seems to work: [:&& [:cast included-uuids [:raw "uuid[]"]] :tzdb.tag_uuids]
The :inline
feature is great for debugging
Iād probably go with :cast
/ :raw
for a situation like that. Open to suggestions on making that easier ā but weāre sort of at the mercy of Clojureās reader for that one.
cast / raw works for me, it just wasn't what I usually write with hugsql