honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
kirill.salykin 2018-05-29T14:28:29.000448Z

hi please advice how I build this query with #honeysql :

SELECT
    CASE 
      WHEN planned_from_date IS NOT NULL THEN
        planned_from_time 
      ELSE
        requested_from_time
      END AS from_time
FROM table

kirill.salykin 2018-05-29T14:28:34.000743Z

thanks

bja 2018-05-29T14:34:37.000884Z

(require '[honeysql.core :as sql]) 
     (require '[honeysql.helpers :refer :all])
     (->> (select [(sql/call :case [:<> :planned-from-date nil] :planned-from-time :requested-from-time) :from-time])
             (from :table)

kirill.salykin 2018-05-29T14:40:22.000861Z

Thanks!

kirill.salykin 2018-05-29T14:44:57.000342Z

Actually seems like there is no ELSE branch

kirill.salykin 2018-05-29T14:46:45.000513Z

Got something like this:

CASE WHEN planned_from_date <> nil THEN planned_from_time END AS from_time,

kirill.salykin 2018-05-29T14:46:59.000252Z

so, almost there 🙂

bja 2018-05-29T14:47:14.000890Z

oops

bja 2018-05-29T14:47:29.000558Z

:else blah

bja 2018-05-29T14:47:36.000553Z

so :else :requested-from-time

bja 2018-05-29T14:48:04.000038Z

that case clause implementation is super weird compared to other parts of honeysql

bja 2018-05-29T14:48:41.000517Z

in general, defer to the tests when there's a question about how something works in honeysql

bja 2018-05-29T14:48:55.000185Z

it's not super well documented in prose, but the test coverage is decent for seeing how the unstated pieces are called

kirill.salykin 2018-05-29T16:37:42.000592Z

Got it, thanks a lot for help!