This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-07
Channels
- # announcements (10)
- # babashka (11)
- # beginners (69)
- # calva (1)
- # cider (2)
- # clj-kondo (35)
- # cljdoc (48)
- # cljs-dev (3)
- # clojure (60)
- # clojurescript (10)
- # community-development (6)
- # cursive (4)
- # datahike (1)
- # datalog (33)
- # deps-new (2)
- # depstar (8)
- # docker (24)
- # fulcro (1)
- # graphql (4)
- # honeysql (5)
- # java (2)
- # leiningen (2)
- # missionary (3)
- # off-topic (104)
- # pedestal (8)
- # polylith (18)
- # portkey (3)
- # reagent (7)
- # reveal (1)
- # rewrite-clj (4)
- # shadow-cljs (19)
- # specter (3)
- # tools-deps (2)
Hi. I'm trying to figure out a way to get the containment operator from Postgres registered with honeysql in a good way.
The @>
operator does not easily represent as a keyword in clojure because of the @ character.
So while I could do (honey.sql/register-op! (keyword "@>"))
, I would then have to refer to the operator via (keyword "@>")
everywhere I want to use it. 😕
@snorremd I would just define a global somewhere with an mnemonic name for it:
(def at> (keyword "@>"))
...
(sql/register-op! at>)
...
(sql/format ... at> ...)
(given Clojure's restrictions on using @
there's really not much else you can do -- this applies to a number of PostgreSQL "enhancements" that use weird characters)
Thanks! Did not think about just defining a global. I made a function instead with infix notation:
(defn- contains-formatter [_f args]
(let [[sql & params] (hsql/format-expr-list args)]
(into [(str (first sql) " @> " (second sql))]
(flatten params))))
(hsql/register-fn! :at> contains-formatter)
This seems to work reasonably well, but yours is simpler. 🙂