honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
troglotit 2018-08-03T14:22:01.000138Z

does anyone have example of WITH expression?

troglotit 2018-08-03T14:22:41.000380Z

There’s no documentation, and I can’t find out why it produces invalid query

troglotit 2018-08-03T14:22:56.000439Z

(-> (helpers/with [(-> (helpers/select :upc.amount :upc.id :pc.expires_at)
                         (helpers/from [:user_promo_codes :upc])
                         (helpers/join [:promo_codes :pc] [:= :pc.code :upc.promo_code_id])
                         (helpers/where [:and
                                         [:> :pc.expires_at (time/now)]
                                         [:= :upc.user_id user_id]]))
                     "not_expired"])
      (helpers/select :*)
      (helpers/from :not_expired)
      (helpers/where [:= :not_expired.amount (-> (helpers/select (sql/call :max :bar.amount))
                                                 (helpers/from :not_expired))])
      (sql/format)
      ((fn [p] (prn p) p))
      (->> (db/execute <db>)))

troglotit 2018-08-03T14:36:17.000273Z

hmm, false alarm, seems like trouble is not with WITH expression

troglotit 2018-08-03T14:39:20.000540Z

hmm, not false alarm slightly_smiling_face made it finally

2018-08-03T22:44:44.000052Z