Fork me on GitHub
#honeysql
<
2022-06-24
>
slipset06:06:39

One little gotcha that we’ve stumble upon is that something like

(-> (hh/delete-from :foo) (hh/where (map clauses nil-xs)))
might lead to something rather unexpected, ie instead of deleting nothing, you delete everything. We’ve introduced a sentinel value ::all to use when we really want all and and throw if we “accidentally” pass something that leads to hh/where returning empty

seancorfield16:06:33

@slipset HoneySQL has a couple of modes where it highlights "unusual" conditions etc -- do you think it would be worth a check on :delete-from to ensure it has a non-empty condition and warn/throw on that?

slipset16:06:29

Not sure what would be a general solution, but I’ve done this in our specific case.

slipset16:06:48

Basically just providing a problem with one possible solution 🙂

slipset16:06:27

One could argue that this would be a problem with update as well. I know I’ve fat fingered updates without clauses in a console.

seancorfield16:06:13

Read over what :checking does in https://cljdoc.org/d/com.github.seancorfield/honeysql/2.2.891/doc/getting-started?q=checking#format-options and let me know if you think extending that to delete from and update would help (by creating an issue). Someone who genuinely wants to delete/update all rows could added a dummy true condition to suppress it (which I see a lot of people doing in SQL anyway with WHERE 1 = 1)

slipset20:06:17

I guess (hh/where nil) could be flagged?

slipset20:06:22

I’ll open an issue