sql

All things SQL and JDBC...
dharrigan 2020-04-14T19:49:32.251Z

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

dharrigan 2020-04-14T19:50:05.251700Z

...LEFT JOIN foo ON <http://bar.id|bar.id> = <http://foo.id|foo.id> AND bar.name = 'wibble'

dharrigan 2020-04-14T19:50:31.252300Z

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

seancorfield 2020-04-14T20:19:52.253200Z

(left-join :foo [:and [:= :<http://bar.id|bar.id> :<http://foo.id|foo.id>] [:= :bar.name "wibble"]]) should work I think?

dharrigan 2020-04-14T20:21:09.253500Z

I think I tried that, but reattempting

seancorfield 2020-04-14T20:21:56.253700Z

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

dharrigan 2020-04-14T20:21:58.253900Z

no joy

dharrigan 2020-04-14T20:22:10.254300Z

ah, try if you have multiple left-joins

dharrigan 2020-04-14T20:24:01.255300Z

(left-join :foo [:and [:= :<http://bar.id|bar.id> :<http://foo.id|foo.id>] [:= :bar.name "wibble"]]
                :a [:= <http://a.id|a.id> :<http://b.id|b.id>])

seancorfield 2020-04-14T20:24:05.255400Z

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

dharrigan 2020-04-14T20:24:11.255600Z

ah I see

seancorfield 2020-04-14T20:24:13.255900Z

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

seancorfield 2020-04-14T20:24:43.256300Z

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

dharrigan 2020-04-14T20:33:15.257Z

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