sql

All things SQL and JDBC...
2021-05-26T16:27:37.033500Z

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

2021-05-26T16:35:50.034Z

Some suggestions for improvement?

seancorfield 2021-05-26T16:48:18.035100Z

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

seancorfield 2021-05-26T16:50:46.035600Z

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

2021-05-28T13:09:18.043200Z

I use HoneySQL v2 and merge-where helper is not here anymore. What replaces it please?

2021-05-28T13:37:29.043600Z

OK just where, right? I see the generic function.

2021-05-28T20:02:03.059200Z

Awesome, thx!

2021-05-26T16:52:58.036200Z

Perfect, thank @seancorfield

2021-05-26T18:44:07.037700Z

Yeah, I like the cond-> style too.. Brilliant!