Fork me on GitHub
#honeysql
<
2023-04-30
>
marrs21:04:35

I've just noticed that :join and :inner-join get added to a query in a different order when combined with :left-join. Is that deliberate?

seancorfield21:04:18

The DSL is a hash map: it is inherently unordered. There's a :join-by construct in the DSL if you need JOINs in a specific order for your database (the behavior with multiple JOINs differs between databases... because of course it does).

marrs12:05:45

Thanks, I switched to that already. I just wondered if I was missing a trick. I've noticed that hashmaps tend to be ordered by key alphabetically, and since inner-join and join are both ahead of left-join, I was wondering if you were forcing the behaviour for some reason.

seancorfield16:05:18

Small hash maps stay in key order because they use an array but that's a pure implementation detail and should never be relied on:

user=> {:b 2 :a 1}
{:b 2, :a 1}
What HoneySQL does is process clauses in "precedence order" and it uses a vector to determine that, so I've probably got all the JOIN-related clauses in alphabetical order just for maintenance purposes: https://github.com/seancorfield/honeysql/blob/develop/src/honey/sql.cljc#L1228-L1238 but modified by https://github.com/seancorfield/honeysql/blob/develop/src/honey/sql.cljc#L709-L717