Skip to content

refactor(query-builder)!: remove logQuery method#12220

Open
pkuczynski wants to merge 1 commit intomasterfrom
refactor/remove-logquery
Open

refactor(query-builder)!: remove logQuery method#12220
pkuczynski wants to merge 1 commit intomasterfrom
refactor/remove-logquery

Conversation

@pkuczynski
Copy link
Member

The logQuery() method (previously printSql) was redundant — all executed queries are already logged automatically through the configured logger when the query is actually run via QueryRunner. The method was also misleading: it was gated by the logging DataSource option, so it silently did nothing when logging was disabled (the default).

  • Remove logQuery() from QueryBuilder
  • Update query builder docs to recommend getSql() / getQueryAndParameters() for SQL inspection and logging: ["query"] for automatic query logging
  • Update migration guide: change "printSql renamed to logQuery" to "printSql removed" with alternatives

The logQuery() method (previously printSql) was redundant — all
executed queries are already logged automatically through the
configured logger. Use getSql() or getQueryAndParameters() to
inspect SQL, or enable logging: ["query"] in DataSource options.
@pkuczynski pkuczynski self-assigned this Mar 15, 2026
@qodo-free-for-open-source-projects

Review Summary by Qodo

Remove redundant logQuery method and update documentation

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Remove redundant logQuery() method from QueryBuilder
• Update migration guide with removal details and alternatives
• Enhance query builder docs with SQL inspection examples
• Recommend getSql() and DataSource logging configuration
Diagram
flowchart LR
  QB["QueryBuilder<br/>logQuery method"] -- "removed" --> REMOVED["Method removed"]
  REMOVED -- "use instead" --> GETSQL["getSql()/<br/>getQueryAndParameters()"]
  REMOVED -- "for logging" --> LOGGING["DataSource<br/>logging option"]
  DOCS1["Migration Guide"] -- "updated" --> DOCS1_OUT["printSql removed<br/>with alternatives"]
  DOCS2["Query Builder Docs"] -- "enhanced" --> DOCS2_OUT["SQL inspection<br/>examples added"]
Loading

Grey Divider

File Changes

1. src/query-builder/QueryBuilder.ts ✨ Enhancement +0/-9

Remove logQuery method from QueryBuilder

• Removed logQuery() method from QueryBuilder class
• Method delegated to configured logger via getQueryAndParameters()
• Eliminated redundant functionality already provided by automatic query logging

src/query-builder/QueryBuilder.ts


2. docs/docs/guides/8-migration-v1.md 📝 Documentation +18/-6

Update migration guide for printSql removal

• Updated section title from "printSql renamed to logQuery" to "printSql removed"
• Clarified that method was redundant due to automatic query logging
• Added code examples showing getSql() / getQueryAndParameters() alternatives
• Added example of enabling query logging via DataSource logging option

docs/docs/guides/8-migration-v1.md


3. docs/docs/query-builder/1-select-query-builder.md 📝 Documentation +17/-5

Update query builder docs with SQL inspection guidance

• Replaced logQuery() example with getSql() inspection approach
• Added detailed explanation of getSql(), getQuery(), and getQueryAndParameters() methods
• Added code example showing SQL output with parameter placeholders
• Added section on automatic query logging via DataSource configuration

docs/docs/query-builder/1-select-query-builder.md


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link

qodo-free-for-open-source-projects bot commented Mar 15, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Misdocumented getQuery behavior 🐞 Bug ✓ Correctness
Description
The SelectQueryBuilder docs state that getQuery() returns the same SQL string as getSql(), but
getQuery() explicitly returns SQL without parameters being replaced while getSql() returns the
driver-escaped SQL produced via escapeQueryWithParameters(). This can mislead users into using
getQuery() expecting driver-specific placeholders (e.g., $1) and/or the same output as
getSql().
Code

docs/docs/query-builder/1-select-query-builder.md[R815-816]

+`getSql()` returns the SQL with parameter placeholders. `getQuery()` returns the same SQL string. To also see the parameter values, use `getQueryAndParameters()` which returns a `[sql, parameters]` tuple.
+
Evidence
The docs claim getQuery() and getSql() return the same SQL, but the implementation documents and
enforces a semantic difference: getQuery() returns SQL with parameters not replaced, whereas
getSql() is derived from escapeQueryWithParameters(getQuery(), getParameters()).

docs/docs/query-builder/1-select-query-builder.md[801-816]
src/query-builder/SelectQueryBuilder.ts[79-96]
src/query-builder/QueryBuilder.ts[470-488]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The docs claim `getQuery()` returns the same SQL string as `getSql()`, but in code `getQuery()` is explicitly &quot;without parameters being replaced&quot; while `getSql()` is derived from `escapeQueryWithParameters(getQuery(), getParameters())`.

## Issue Context
This is user-facing documentation in the QueryBuilder guide and can cause confusion when users expect `getQuery()` to show driver-specific placeholders (e.g., `$1`) like `getSql()`.

## Fix Focus Areas
- docs/docs/query-builder/1-select-query-builder.md[801-816]
- src/query-builder/SelectQueryBuilder.ts[79-96]
- src/query-builder/QueryBuilder.ts[470-488]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 15, 2026

commit: 1bbad95

@sonarqubecloud
Copy link

@cloudflare-workers-and-pages
Copy link

Deploying typeorm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1bbad95
Status: ✅  Deploy successful!
Preview URL: https://4752a54a.typeorm.pages.dev
Branch Preview URL: https://refactor-remove-logquery.typeorm.pages.dev

View logs

@coveralls
Copy link

Coverage Status

coverage: 73.185% (-0.001%) from 73.186%
when pulling 1bbad95 on refactor/remove-logquery
into 0b8e937 on master.

```

This query will return users and log the used sql statement through the configured logger.
`getSql()` returns the SQL with parameter placeholders. `getQuery()` returns the same SQL string. To also see the parameter values, use `getQueryAndParameters()` which returns a `[sql, parameters]` tuple.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do getSql() and getQuery() really return the same SQL string?

Copy link
Collaborator

@alumni alumni Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they do not :)

There's a slight difference: in getSql the query parameters are substituted.

@alumni
Copy link
Collaborator

alumni commented Mar 20, 2026

@naorpeled I'm going to leave this up to you, since you looked into it before.

I remember we also discussed the utility of this function when we chatted about renaming it from logSql to logQuery. IIRC the argument against this removal was that you can create a partial QueryBuilder in one place and it's an easy alternative to console.log when developing.

Feel free to directly close or merge this PR.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants