honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
orestis 2021-06-23T07:28:50.079700Z

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

2021-06-23T12:12:03.080600Z

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

seancorfield 2021-06-23T15:42:05.080800Z

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)"]

orestis 2021-06-23T17:25:40.081100Z

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

john-shaffer 2021-06-23T17:31:40.081300Z

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-shaffer 2021-06-23T17:33:29.081500Z

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-shaffer 2021-06-23T17:35:04.081800Z

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

seancorfield 2021-06-23T17:45:26.082Z

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!.

♥️ 1
seancorfield 2021-06-23T17:46:11.082200Z

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