Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: include query name in PreparedQuery type #522

Open
PhilipTrauner opened this issue May 10, 2023 · 3 comments
Open

Suggestion: include query name in PreparedQuery type #522

PhilipTrauner opened this issue May 10, 2023 · 3 comments

Comments

@PhilipTrauner
Copy link

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 queryName field to PreparedQuery
  • substitute in an escape version of typeDec.query.name in generateDeclarationFile
@timvandam
Copy link

This is something I would definitely use

@KieranKaelin
Copy link

KieranKaelin commented Aug 11, 2023

Any update on this? Would be a great feature.

@logan12358
Copy link
Contributor

Just created #546 for consideration to implement this.

As additional context, before 3c99d10 (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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants