alexdesousa / ayesql

Library for using raw SQL in Elixir
MIT License
135 stars 13 forks source link

Mandatory parameter with a default? #29

Closed dvv closed 2 years ago

dvv commented 2 years ago

Hi!

I wonder can we have the subj?

For example I repeatedly have a bunch of filtering queries of the form:

SELECT * FROM foo WHERE coalesce(c1 = :c1, true) AND coalesce(c2 = :c2, true) ...AND coalesce(cN = :cN, true)

The problem then that I have to pass the full keyword list [c1: nil, c2: nil, ...cN: "bebebe"] to the runner each and every time I use the query.

I would instead rather pass simpler [cN: "bebebe"] at application level. And have the library doing kinda boring args ++ [c1: nil, c2: nil, ...cN: nil] in private. I believe it is possible since the library does know (right?) the set of parameter names.

To distinguish from a truly mandatory parameter I'd propose using either :name:nil (drawback that nil is not an sql term) or :?name.

Was I clear? Do you think it's feasible? possible?

TIA