I'm not really familiar with parsec, so I don't think it's the best way, but I think it's a pretty simple solution. I'm proposing an escape sequence of two consecutive dollar-signs. The parser is simple enough, if we find a $, try to consume another $, otherwise try to get an identifier. Example:
query :: Text -> Text
query fields = [text| SELECT $fields FROM foobar WHERE id=$$1 ]
Calling query "id, name" should output SELECT id, name FROM foobar WHERE id=$1. It should also work on silly strings like $$$a$$$b$$${a_long_identifier}$$.
I'm not really familiar with parsec, so I don't think it's the best way, but I think it's a pretty simple solution. I'm proposing an escape sequence of two consecutive dollar-signs. The parser is simple enough, if we find a
$
, try to consume another$
, otherwise try to get an identifier. Example:Calling
query "id, name"
should outputSELECT id, name FROM foobar WHERE id=$1
. It should also work on silly strings like$$$a$$$b$$${a_long_identifier}$$
.