honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
nachos 2020-05-29T13:01:51.045500Z

How would I translate this query into honeysql?

SELECT name, dt_expire < NOW() as expired from ......

seancorfield 2020-05-29T15:05:51.046900Z

;; 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

1
Johannes F. Knauf 2020-05-29T15:29:43.049700Z

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

seancorfield 2020-05-29T15:41:53.050500Z

I find the DSL based on the helpers a lot easier to read. It avoids a lot of [ .. ] and reads more like code.

seancorfield 2020-05-29T15:43:27.051800Z

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.

seancorfield 2020-05-29T20:48:45.054800Z

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

👍 8
❤️ 1