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)
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!
@kirill.salykin Some people prefer working with the maps, some people prefer the helpers.
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])
@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?
I will try on Monday, thx. No need a sub-select in my case.
so the personal preference is the only difference?
@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.
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).
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.
i see big thanks for such detailed explanation!