diff --git a/lib/database.js b/lib/database.js index daa0e45..11d8ff2 100644 --- a/lib/database.js +++ b/lib/database.js @@ -1,6 +1,9 @@ 'use strict'; const { Pool } = require('pg'); +const { createHash } = require('node:crypto'); + +const hash = (data) => createHash('sha1').update(data).digest('base64'); const removePadding = (s) => { const chunks = s.split('\n').map((d) => d.trim()); @@ -274,11 +277,17 @@ class Database { this.model = options.model || null; } - query(sql, values) { + query(text, values) { const data = values ? values.join(',') : ''; - this.console.debug(`${sql}\t[${data}]`); + this.console.debug(`${text}\t[${data}]`); + + const args = { + text, + values, + }; + if (values) args.name = hash(text); - return this.pool.query(sql, values).catch((error) => { + return this.pool.query(args).catch((error) => { error.dbStack = error.stack; Error.captureStackTrace(error); throw error;