Fork me on GitHub
#sql
<
2020-04-14
>
dharrigan19:04:32

Is there a way, in honeysql, to represent this?

dharrigan19:04:05

...LEFT JOIN foo ON = AND bar.name = 'wibble'

dharrigan19:04:31

I tried a few things, like nesting vectors in the honeysql (left-join clause, but it no work, cap'tain!

seancorfield20:04:52

(left-join :foo [:and [:= : :] [:= :bar.name "wibble"]]) should work I think?

dharrigan20:04:09

I think I tried that, but reattempting

seancorfield20:04:56

user=> (-> (select :* :bar) (left-join :foo [:and [:= : :] [:= :bar.name "wibble"]]) (h/format))
["SELECT *, bar LEFT JOIN foo ON ( =  AND bar.name = ?)" "wibble"]

dharrigan20:04:10

ah, try if you have multiple left-joins

dharrigan20:04:01

(left-join :foo [:and [:= : :] [:= :bar.name "wibble"]]
                :a [:=  :])

seancorfield20:04:05

If you have multiple joins, you have to use the merge- helpers

seancorfield20:04:13

user=> (-> (select :* :bar) (merge-left-join :foo [:and [:= : :] [:= :bar.name "wibble"]]) (merge-left-join :quux [:and [:= : :] [:= :foo.thing "wut"]])  (h/format))
["SELECT *, bar LEFT JOIN foo ON ( =  AND bar.name = ?) LEFT JOIN quux ON ( =  AND foo.thing = ?)" "wibble" "wut"]

seancorfield20:04:43

Each left-join / merge-left-join phrase only joins one table.

dharrigan20:04:15

That's Sean! Using a series of (merge-left-join...) solved it