honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
2020-07-24T08:34:05.288600Z

My use case is to batch-insert a lot of data from one db to another one. I am currently using honeysql to create by sql query, but I only need the sql part and not the values. I wonder if there is a simpler way to get the sql string:

(-> (h/insert-into :product)
    (h/columns :product/id
               :product/name)
    (h/values [[123 "foobar"]]) ; dummy values, won't be used
    sql/format
    first)

kirill.salykin 2020-07-24T11:02:21.290900Z

Goodmorning there are two ways to create query: with helpers (1) and with a map (2) what are the differences and when you should prefer one over other? is map (2) considered as internal represantation? or maybe helpers (1) do a bit more then just massaging the map? Thanks!

seancorfield 2020-07-24T16:19:11.291400Z

@kirill.salykin Some people prefer working with the maps, some people prefer the helpers.

seancorfield 2020-07-24T16:20:38.293Z

Some helpers are "smart" in that they add to, rather than replace what's in the map: merge-where vs merge for example, so you don't have to think about whether there's already a where clause. But you can do that easily enough with raw hash maps too: (update sql-map :where (fnil conj []) [:= :a 1])

seancorfield 2020-07-24T16:21:41.293900Z

@vincent.cantin I think you can just omit the values clause in that case? But wouldn't you have a sub-select clause in there?

2020-07-24T16:22:17.294300Z

I will try on Monday, thx. No need a sub-select in my case.

kirill.salykin 2020-07-24T17:42:35.295100Z

so the personal preference is the only difference?

seancorfield 2020-07-24T17:51:53.295300Z

@kirill.salykin I'd say so, yes. I prefer the helpers because, to me, they read more easily as a DSL for SQL. Some people prefer raw data structures because they find "pure data" more readable.

seancorfield 2020-07-24T17:52:36.295500Z

When I build HoneySQL 2.0, it will start by formalizing those data structures and then adding an optional DSL (like today's helpers but much more streamlined).

seancorfield 2020-07-24T17:54:03.295700Z

My big challenge will be figuring out how/whether to make it fully backward compatible or not (it will be new namespaces so the 1.x syntax will continue to work and be supported). I mostly want to make it a lot easier to extend and to better support non-ANSI SQL syntax.

👍 2
kirill.salykin 2020-07-24T18:03:19.296500Z

i see big thanks for such detailed explanation!