ReviewOS

stacks/bun-query-builder

Slow-query threshold + populate 'params' in query hooks

#1045
Closed glennmichael123 opened this 2 months ago ·
2 months ago

Summary

QueryHooks + runWithHooks already measure durationMs and fire onQueryStart/onQueryEnd. Two gaps: (a) the params field declared on every hook event is never populated — hooks receive only { sql, kind }, so consumers can't log bound values; (b) no built-in slow-query warning.

Proposal

  • Populate params on the hook events.
  • Add config.hooks.slowQueryThresholdMs (or onSlowQuery) that fires when durationMs exceeds it, reusing the existing timing.

This is also the closest feasible proxy for the connection-leak detection deferred in #1014 (Bun's pool exposes no checkout hooks).

Effort: S. Location: src/client.ts runWithHooks (~2364), src/types.ts QueryHooks (~203). Found via internal code audit.

9 days ago

Done in 71d0d9e. Added QueryHooks.slowQueryThresholdMs + onSlowQuery (reuses the duration already measured; threshold 0 = report all, console.warn fallback when no handler), and the previously-declared-but-empty params are now populated on onQueryStart/End/Error/startSpan (best-effort — sqlite wrapper exposes them as .values). Also routed the prepared-statement fast paths through runWithHooks when slow-query reporting is active so it fires even when configured alone. Regression test added; full suite green.

Sign in to comment on this issue.