Source Code Mapping
Query Doctor can link every query captured by pg_stat_statements back to the application code that produced it — the source file, line number, HTTP route, and request method. This is powered by SQLCommenter tags that your ORM appends as structured SQL comments.
How it works
Section titled “How it works”An SQLCommenter-enabled ORM wraps each query in a comment containing key-value metadata:
/* file='src%2Fusers%2Fservice.ts%3A42%3A5',route='%2Fapi%2Fusers',method='GET',db_driver='drizzle' */SELECT id, name FROM users WHERE active = true;When Query Doctor reads pg_stat_statements, its analyzer extracts these tags and displays them all alongside the query in the Live Queries detail view. Every tag is shown as a key-value pair, but the file tag gets special treatment — when present, Query Doctor renders it as a clickable link that opens the exact file and line in your IDE (see Configuring your IDE below).
Supported tags
Section titled “Supported tags”| Tag | Description |
|---|---|
file | Source file, line, and column (path:line:column) |
route | HTTP route that triggered the query |
method | HTTP request method (GET, POST, etc.) |
db_driver | ORM / driver identifier |
| Custom tags | Any arbitrary key-value pairs you attach |
Trace context (OpenTelemetry span and trace IDs) is included automatically when a tracer is active.
Enabling tags
Section titled “Enabling tags”Install a tracking integration for your database driver or ORM:
- Drizzle —
@query-doctor/sqlcommenter-drizzle - EF Core —
QueryDoctor.SqlCommenter.EFCore— EF Core interceptor that appends tags via stack inspection or explicit context - MikroORM —
@query-doctor/sqlcommenter-mikroorm— uses MikroORM’s built-inonQueryhook - TypeORM —
@query-doctor/sqlcommenter-typeorm— wraps your TypeORMDataSource - node-postgres (pg) —
postgres-tracked-pool— drop-inpg.Poolreplacement that automatically addsfileandfunc_nametags
Once the integration is in place, new queries that hit the database will carry the comment tags. Existing entries in pg_stat_statements won’t have them.
Configuring your IDE
Section titled “Configuring your IDE”When a query has a file tag, the path is rendered as a clickable link. To have it open directly in your editor, configure the IDE selector:
- Open the Live Queries page.
- Click the settings icon in the toolbar.
- Choose your Preferred IDE.
- For JetBrains IDEs, also set the Project path (the local root of your project) so that relative paths resolve correctly.
Supported IDEs
Section titled “Supported IDEs”- Cursor
- VS Code
Uses the vscode://file/path:line:column protocol.
- WebStorm
- PhpStorm
- IntelliJ IDEA
- PyCharm
- GoLand
- RubyMine
- Rider
- CLion
Uses the ide://open?file=path&line=N&column=N protocol. Requires the Project path setting so relative file paths can be resolved to absolute paths on your machine.
Further reading
Section titled “Further reading”- SQLCommenter for Drizzle — installation and framework middleware setup
- SQLCommenter for EF Core — EF Core interceptor setup and configuration
- SQLCommenter for MikroORM — MikroORM
onQueryhook setup - SQLCommenter for TypeORM — TypeORM DataSource wrapper setup
- SQLCommenter specification