Fork me on GitHub
AJ Jaro20:12:43

I’m on a super old version of honeysql (1.0.444) and we have a bunch of places in the code that developers put in to protect ourselves before running a query with an empty collection. For a simple example, select (); obviously returns an error (at least in postgres), so we’ve written a number of (when (seq data) (select data)) Is there something built-in to a newer version that prevents that query from being run since it’s invalid? If not, I’m pretty sure we could write some internal tooling to prevent that instead


@ajarosinski There's nothing specifically, right now, but there is now the concept of a "checking" mode (`:checking :none|:basic|:strict`) which enables certain checks and assertions in the formatted so adding logic to throw an exception if :select has an empty? collection argument would be pretty easy. It was originally added to check IN () clauses but I could extend it to SELECT clauses to -- and anything else folks want.

AJ Jaro20:12:58

Hmm, that sounds kind of interesting. I was actually thinking for the in clause. Do you mean that you already have it for that form!?


Yes, if you say {:checking :basic} or {:checking :strict} in the options to sql/format (new version) then it throws if IN would have an empty set of values.


I'm just adding a similar check for SELECT and similar constructs.


Just pushed that to develop. I'll cut a new release soon, I expect.


2.1.833 is available.

👏 1

If you create an issue on the honeysql repo, I'll add that -- and any other "lint"-like checks folks can think of.

seancorfield21:12:26 -- includes a bug fix for merging select-distinct-on and expands the "lint"-like checks to SELECT and a bunch of other clauses that expect a non-empty list of columns (when :checking is :basic or :strict -- by default, checking is :none).

❤️ 1