Comment

Comment by Diggsey

FWIW, you very rarely need to make the query itself dynamic. After all, SQL alone is powerful enough to do conditionals.

For example:

    SELECT * FROM example
    WHERE ($1 IS NULL OR field1 = $1)
    AND ($2 IS NULL OR field2 = $2)
    ...

When you supply the parameters to this prepared statement, the constant conditions should be optimized away by the query planner if you're using a decent database.
parent Diggsey 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton