Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pgClient.query = function(...args: Array): any {
const [a, b, c] = args;
// If we understand it (and it uses the promises API)
if (
(typeof a === 'string' && !c && (!b || Array.isArray(b))) ||
(typeof a === 'object' && !b && !c)
) {
if (debugPg.enabled) {
// Debug just the query text. We don’t want to debug variables because
// there may be passwords in there.
debugPg('%s', formatSQLForDebugging(a && a.text ? a.text : a));
}
if (pgClient._explainResults) {
const query = a && a.text ? a.text : a;
const values = a && a.text ? a.values : b;
if (query.match(/^\s*(select|insert|update|delete|with)\s/i) && !query.includes(';')) {
// Explain it
const explain = `explain ${query}`;
pgClient._explainResults.push({
query,
result: pgClient[$$pgClientOrigQuery]
.call(this, explain, values)
.then((data: any) => data.rows),
});
}
}