haskell-opaleye
haskell-opaleye copied to clipboard
Feature request: query anonymization
I'd like to anonymize SQL queries for logging purposes. This is commonly done by replacing literals with some placeholder, like ?
.
Re-parsing the generated query just to do that seems wasteful, so it seems that the best way to do that would be to modify Opaleye's query generator.
First, would such a feature be welcome?
Second, what would be the best way to do that? I see two options:
- Use a special SqlGenerator, overriding
sqlLiteral
, or - Add a parameter to
ppSqlExpr
, which would influence how ConstSqlExpr is printed.
Both options require many changes in the code, to pass the "printing mode" parameter deep in the call stack, that's why I'm asking for advice on how to proceed.
I'm happy to try to provide guidance. How do you imagine this being used? A new top-level function like showSql
except that it replaces literals? SqlGenerator
s were the way that HaskellDB supported selectively replacing parts of the pretty printer. Opaleye hasn't kept up rigorously with that, although we could.
A new top-level function like
showSql
except that it replaces literals?
Exactly that. Here is my work in progress. I've created a showSqlAnonymized
function, which is like showSql
except it outputs literals differently. The remaining thing to do is to provide analogous versions of arrange{Insert,Update,Delete}{,Returning}Sql
.
Ah nice, looks sensible.