honeysql

marrs 2023-04-30T21:13:35.991209Z

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?

marrs 2023-05-01T12:15:45.293649Z

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.

seancorfield 2023-05-01T16:02:18.137429Z

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

seancorfield 2023-04-30T21:29:18.068569Z

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