pgtyped
pgtyped copied to clipboard
Suggestion: include query name in `PreparedQuery` type
Hey @adelsz, would you be open to a PR that adds a queryName field to PreparedQuery?
This would be great for logging purposes, as the name of a query is really useful for debugging.
There would only be two required changes:
- add the
queryNamefield toPreparedQuery - substitute in an escape version of
typeDec.query.nameingenerateDeclarationFile
This is something I would definitely use
Any update on this? Would be a great feature.
Just created #546 for consideration to implement this.
As additional context, before 3c99d10f5cea4e12d889ea91717adc400116cfe9 (in v1.0.0), the query name was included in the (private) QueryAST member on PreparedQuery. It was hacky to access it, but it was handy for a logging wrapper. With the new code, something along these lines:
const runQuery = async <TParamType, TResultType>(
query: PreparedQuery<TParamType, TResultType>,
params: TParamType
): Promise<Array<TResultType>> => {
const startTime = new Date();
try {
return await query.run(params, pool);
} finally {
const time = new Date().getTime() - startTime.getTime();
logger.info(
{ query: { name: query.queryName, time, params } },
'Database query completed'
);
}
};
It would be great to have this ability again :smile:
Was also looking for this feature 👍