Re: Rethinking parameterized SQL queries
Lassi Kortela 27 Feb 2021 09:30 UTC
You could make a general-purpose escaping framework:
- A proper list ( ... ) is rendered as parentheses with each element
rendered in between, space-separated.
- |(| |)| also renders that way.
- |[| |]| same but with square brackets.
- |{| |}| same but with curly braces.
- Strings are written out as strings according to target language
conventions.
- Numbers, booleans as well.
- Any symbol contained in the literal set is written out as a bareword.
The literal set is customizable for different languages, could be a
parameter object. The SQL library could come with a reasonable standard
set which the Postgres/MySQL diehards can extend to cover the latest syntax.
- Any symbol not in the literal set will have to be explicitly spliced
in using ($type value) notation; a more user-friendly notation should be
found. This is somewhat unwieldy, but discourages people from writing
SQL by hand and stashing their queries into reusable procedures.