For this project, I had a few advanced queries (search, dynamic filters) to first do with Clojure Next.jdbc / HoneySQL. Does a query like this sound reasonable to you? https://github.com/prestancedesign/clojure-inertia-pingcrm-demo/blob/main/src/pingcrm/models/users.clj#L16-L35
Some suggestions for improvement?
@admin055 I think that’s fine. Personally, I’d probably use cond->
to thread the various where clauses but that’s just a stylistic issue.
As an example (from part of our codebase still using HoneySQL v1):
([self status exclude items qualifier]
(cond-> (-> (select [:uc.senderuserid :id])
(from [:usercovalence :uc])
(where [:= :uc.receiveruserid (:id self)])
(user-status :uc.senderuserid)
(user-gender :uc.receiveruserid))
;; WS-13047 status must be conditional because it can be nil:
status
(merge-where [:= :uc.covalence status])
qualifier
(merge-where qualifier)
(seq items)
(within-items items :user-id :uc.senderuserid)
(seq exclude)
(merge-where [:not-in :uc.senderuserid exclude])))
I use HoneySQL v2 and merge-where
helper is not here anymore.
What replaces it please?
OK just where
, right? I see the generic
function.
See https://cljdoc.org/d/com.github.seancorfield/honeysql/2.0.0-rc2/doc/differences-from-1-x#helpers
Awesome, thx!
Perfect, thank @seancorfield
Yeah, I like the cond->
style too.. Brilliant!