Command filter for Postgres
The command filter is invoked whenever a command packet is received from the client. This can include the following packet types:
Parameters
Packet types : optional. If specified, a comma-separated list of packet types for which this filter should be called, for instance: Parse,Bind,Close. Spaces are ignored. If this is not specified, all packet types will qualify.
Example
A typical use for this filter would be to set the Packet types parameter to Parse and modify certain SQL statements:
if (context.connectionContext.userName === 'henry' && sql.match(/^delete\s+from\s+customers\b/)) {
log.debug("Ignoring delete from customers for Henry");
context.packet.setQuery("delete from customers where first_name='IgnoreIgnoreIgnore'");
}
This will ensure that the delete will not actually delete anything, yes the database will respond appropriately.