honeysql

2023-11-23T13:02:04.254849Z

2023-11-23T17:36:27.462599Z

jose 2023-11-23T19:50:45.201189Z

Is it possible to write this query with honeysql?

select *
from foo
left join bar on (foo.id = bar.foo_id AND (bar.x = 'baz'))
where foo.label = 'xxx';

p-himik 2023-11-23T19:55:27.638749Z

Of course.

(sql/format {:select    :*
             :from      :foo
             :left-join [:bar
                         [:and [:= :foo/id :bar/foo-id] [:= :bar/x "baz"]]]
             :where     [:= :foo/label "xxx"]})
=> ["SELECT * FROM foo LEFT JOIN bar ON (foo.id = bar.foo_id) AND (bar.x = ?) WHERE foo.label = ?" "baz" "xxx"]

p-himik 2023-11-23T19:55:42.555819Z

If you need those strings to be inlined, just wrap them in [:inline ...].

👍 1
jose 2023-11-23T20:15:23.491569Z

thanks! I was getting an error, I thought it was an issue with the generated query, but after your response I noticed I did I typo on my original query. Also thanks for pointing me to [:inline ...] :)

👍 1