Conditional segment based on variables?

Is there still no way to do conditional queries based on variables?

like

select * from data
if {{ username }} where username = {{ username }}

Is the goal to run the SQL even if the variable is empty? You can make SQL parameters (or clauses with paramters) optional like this:

SELECT *
FROM test_users
[[WHERE username = {{username}}]]

It's that, but also other scenarios.

One scenario, I have three values I want to query based on. But these values are not very human friendly, so I want a drop down of options, then it queries using the correct value.

For example, drop down item would be "Widget Blue", but the query would use value = 'wid543jj33'

Another scenerio, I create queries that are 30 days, 1 year and so on, and right now I have to create separate ones as I want "Month", "Year" as options in the drop down, but instead I have to use magic numbers 30 and 365.

Also, your scenerio only works with one parameter, or 2+. If I have potentially two variables, I'd need some way to know to use where clause on one and and on other. If the first option isn't chosen, then the where clause wouldn't be there, and I'd have to do it for the second parameter.

It gets even more complicated when it isn't just simple 30 days and some other form of math.

Ideally, I would want a way to have key/value option for variables where what you see in the dropdown is not necesarily what you add to the query. Also some conditional options so it can be even smarter.