Fork me on GitHub
#honeysql
<
2021-02-11
>
seancorfield00:02:41

Progress report! WITH is back to supporting multiple CTEs (and there's even a test for it); I have "finished" the clause reference mentioned above; I have incorporated all of the SQL portions from the nilenso/honeysql-postgres library (although some of the syntax has ended up a little different (HoneySQL v2's :insert-into supports an alias out of the box so insert-into-as is not needed, and do-update-set! is not needed because HoneySQL v2's :do-update-set clause supports both the simple excluded case and the full SET-like version). See https://github.com/seancorfield/honeysql/blob/v2/test/honey/sql/helpers_test.cljc#L281-L332 for the HoneySQL v2 tests of helpers like the nilenso functions.

4
seancorfield00:02:53

Next up: add the DDL from nilenso/honeysql-postgres (and document those clauses) and comb through the source and tests in that library to see if there's anything that isn't documented in the README.

seancorfield00:02:34

Then I'll continue on through the open issues for v2 and documentation and figure out at what point it will be worth cutting an alpha release to clojars. The latest SHA for anyone playing with the :git/url version is e157aec976769e4cfad0e63f0bad665ba5068e01.

dharrigan21:02:27

So, just getting round to "port" my existing application to honeysql v2. Am I right in thinking that this style is no longer in use (or rather no longer encouraged)...

dharrigan21:02:54

(-> (select :device-id)
        (helpers/from :trip)
        (where [:= :vrn vrn]
               [:= :tenant-id tenant-id]
               [:>= :start-datetime (db/datetime->sql from)]
               [:<= :end-datetime (db/datetime->sql to)])
        (limit 1)
        sql/format)))

dharrigan21:02:01

and should be replaced with {} maps?

dharrigan21:02:28

(sql/format
  {:select [:device-id]
   :from [:trip]
   :where [:and [:= :vrn "asd"]
                [:= :tenant-id "tenant-id"]
                [:>= :start-datetime "from"]
                [:<= :end-datetime "to"]]
   :limit 1})
;; ["SELECT device_id FROM trip WHERE (vrn = ?) AND (tenant_id = ?) AND (start_datetime >= ?) AND (end_datetime <= ?) LIMIT ?"
;;  "asd"
;;  "tenant-id"
;;  "from"
;;  "to"
;;  1]

seancorfield21:02:08

honey.sql.helpers has all the helpers you are used to.

seancorfield21:02:04

@dharrigan

user=> (-> (select :device-id)
  #_=>         (helpers/from :trip)
  #_=>         (where [:= :vrn vrn]
  #_=>                [:= :tenant-id tenant-id]
  #_=>                [:>= :start-datetime (db/datetime->sql from)]
  #_=>                [:<= :end-datetime (db/datetime->sql to)])
  #_=>         (limit 1)
  #_=>         sql/format)
["SELECT device_id FROM trip WHERE (vrn = ?) AND (tenant_id = ?) AND (start_datetime >= ?) AND (end_datetime <= ?) LIMIT ?" "vrn" 42 #inst "2021-02-11T21:43:31.289-00:00" #inst "2021-02-11T21:43:31.289-00:00" 1]
🎉