How would I translate this query into honeysql
?
SELECT name, dt_expire < NOW() as expired from ......
;; assuming require [honeysql.core :as sql], [honeysql.helpers :refer [select from]]
(-> (select :name [(sql/call :< :dt_expire (sql/call :now)) :expired])
(from :table)
(sql/format)))
;=> ["SELECT name, dt_expire < now() AS expired FROM table"]
^ @danisam17@seancorfield Any deeper reason to prefer the function threading variant over pure data?
{:select [:name [(sql/call :< :dt_exire (sql/call :now)) :expired]]
:from [:table]}
I was asking this question myself all the time since starting to use honeysql.I find the DSL based on the helpers a lot easier to read. It avoids a lot of [
.. ]
and reads more like code.
Also, I tend to write a lot of composable SQL so I pass a query (data structure) into a function and then thread it through functions that augment the query -- so that avoids having to deal with updating/merging vs assoc'ing.
FYI: Justin Kramer, the original project author, has transferred HoneySQL to my GitHub account https://github.com/seancorfield/honeysql and I'm working toward a 1.0 release. The codebase has been updated to use modern ClojureScript so the macrovich dependency has been dropped and the project has been switched to Clojure CLI / deps.edn
and so the dev/test infrastructure is a lot simpler now -- and it has CI configured for both CircleCI and GitHub Actions! The code examples in the readme are automatically checked (via the seancorfield/readme library).