Fork me on GitHub
#honeysql
<
2021-06-23
>
orestis07:06:50

Here's a touch one: Can we use operators that are not valid clojure keywords? Postgresql has some array operators that contain @ , particularly @> and <@

thumbnail12:06:03

You could use (keyword "<@") at the very least

seancorfield15:06:05

dev=> (def at> (keyword "@>"))
#'dev/at>
dev=> (def <at (keyword "<@"))
#'dev/<at
dev=> (sql/register-op! at>)
nil
dev=> (sql/register-op! <at)
nil
dev=> (sql/format {:select :* :from :foo :where [:and [at> :a :b] [<at :c :d]]})
["SELECT * FROM foo WHERE (a @> b) AND (c <@ d)"]

orestis17:06:40

Ah nice. I forgot that you can make keywords which are valid but "unreadable".

john-shaffer17:06:40

I do exactly this, but are the warnings on https://clojuredocs.org/clojure.core/keyword still valid?

;; keyword does not validate input strings for ns and name, and may
;; return improper keywords with undefined behavior for non-conformant
;; ns and name.
;; Warning - the following generated keywords are non-conformant and may wreak
;; serious havoc in the near/far future when least expected...
iirc undefined === "behavior can change at any time"

john-shaffer17:06:29

I don't think it's a big deal here, but I see a lot of places where people e.g. take arbitrary JSON as input and decode with keyword keys, and it seems pretty scary if the result is undefined

john-shaffer17:06:04

Should I be a stickler about using string keys, or are keywords actually fine?

seancorfield17:06:26

The core team did at one point try to tighten up what keywords the reader accepted but it broke quite a bit of code out there — so they reverted that change. I think at this point you are “safe” creating unreadable keywords via keyword as long as you don’t actually try to read them!.

♥️ 2
seancorfield17:06:11

(and, in particular, http://clojuredocs.org is not official documentation so examples and commentary are what random community members think 🙂 )