Named placeholders #1
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
opium
is based onlibpq
, which only supports numbered placeholders out of the box, i.e.is possible but
isn't (note: the placeholder syntax should be considered pseudocode as it depends on the library). One of my goals for this library is supporting the latter, offering a record-centric interface for both serializing and deserializing values. In order to bolt support for this onto
libpq
, we need a way to transform the queryinto
There's several issues to consider here:
libpq
parameter interpolation for actually inserting the values.In my opinion, parameters should only be replaced at the term level, not within quoted identifiers or strings, e.g.
However, doing this "right" requires that all the quotes in the given query are lexed, i.e. a full lexer for PostgreSQL. Libraries that occupy a similar level of abstraction in other languages usually don't do this either, e.g.
psycopg2
(Python)Simple string substitution, see e.g. here.
Uses
%(<name>)<format>
as named placeholder, where<format>
is one ofs
(auto),t
(text) andb
(binary).sqlx
(Go)Simple string substitution, see e.g. here.
Uses
:<name>
as named placeholder. Also does some magic for arrays.Suggested Solution
Support named parameters by simple string interpolation. Suggested format:
%(<name>)
, where<name>
may contain Haskell identifier characters (or more).%%
to insert a literal%
.