Skip to content

docs: add JsonContains find-options example - #11945

Merged
mguida22 merged 2 commits into
typeorm:masterfrom
lraveri:docs/11940-jsoncontains-find-options
Jan 27, 2026
Merged

mguida22 merged 2 commits into
typeorm:masterfrom
lraveri:docs/11940-jsoncontains-find-options

Conversation

@lraveri

@lraveri lraveri commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

Adds a JsonContains example to the Find Options docs.

Fixes #11940.

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

Copy link
Copy Markdown

User description

Adds a JsonContains example to the Find Options docs.

Fixes #11940.


PR Type

Documentation


Description

  • Adds JsonContains find-options example to documentation

  • Includes TypeScript usage and generated SQL query


Diagram Walkthrough

flowchart LR
  A["Find Options Documentation"] -- "adds JsonContains example" --> B["JsonContains Usage Example"]
  B -- "shows TypeScript code" --> C["Code Example"]
  B -- "shows SQL query" --> D["Postgres Query"]
Loading

File Walkthrough

Relevant files
Documentation
3-find-options.md
Add JsonContains find-options documentation example           

docs/docs/working-with-entity-manager/3-find-options.md

  • Adds new JsonContains section to find-options documentation
  • Includes TypeScript import and usage example with
    dataSource.getRepository(Post).findBy()
  • Provides corresponding PostgreSQL query using JSONB @> operator
  • Positioned between array operators and Raw operator sections
+16/-0   

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

qodo-free-for-open-source-projects Bot commented Jan 26, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Impact
General
Fix PostgreSQL cast operator spacing

Remove the space before the ::jsonb cast operator in the SQL example to follow
standard PostgreSQL syntax.

docs/docs/working-with-entity-manager/3-find-options.md [546-548]

 ```sql
-SELECT * FROM "post" WHERE "metadata" ::jsonb @> '{"author":{"name":"John"}}'
+SELECT * FROM "post" WHERE "metadata"::jsonb @> '{"author":{"name":"John"}}'


- [ ] **Apply / Chat** <!-- /improve --apply_suggestion=0 -->


<details><summary>Suggestion importance[1-10]: 3</summary>

__

Why: The suggestion correctly identifies a stylistic issue in an SQL example within the documentation, proposing a change to use the more canonical syntax for the PostgreSQL cast operator.

</details></details></td><td align=center>Low

</td></tr>
<tr><td align="center" colspan="2">

- [ ] More <!-- /improve --more_suggestions=true -->

</td><td></td></tr></tbody></table>

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

qodo-free-for-open-source-projects Bot commented Jan 26, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review


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

Grey Divider

Previous review results

Review updated until commit 6d4f931

Results up to commit 7fb5074


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

Grey Divider
Remediation recommended
1. Missing database compatibility warning for JsonContains 🐞 Bug ⛯ Reliability
Description
• The documentation adds the JsonContains operator without explicitly warning that it only works
  on PostgreSQL and CockroachDB databases
• Users on MySQL, SQL Server, Oracle, or other databases will encounter SQL syntax errors at runtime
  if they use this operator
• The parenthetical "(Postgres notation)" in the SQL example is insufficient - it appears only as a
  comment and doesn't clearly warn about database limitations
• This differs from the pattern where database-specific features should have clear compatibility
  warnings to prevent runtime failures
Code

docs/docs/working-with-entity-manager/3-find-options.md[R534-548]

+- `JsonContains`
+
+```ts
+import { JsonContains } from "typeorm"
+
+const loadedPosts = await dataSource.getRepository(Post).findBy({
+    metadata: JsonContains({ author: { name: "John" } }),
+})
+```
+
+will execute following query (Postgres notation):
+
+```sql
+SELECT * FROM "post" WHERE "metadata" ::jsonb @> '{"author":{"name":"John"}}'
+```
Evidence
The implementation uses hardcoded Postgres-specific SQL syntax without database type checking, and
tests confirm Postgres-only support. The documentation follows the same pattern as
ArrayContains/ArrayOverlap which also lack database warnings, but this doesn't make it correct - it
represents a documentation quality issue that should be addressed.

src/query-builder/QueryBuilder.ts[1083-1084]
src/query-builder/QueryBuilder.ts[1097-1105]
test/github-issues/9664/issue-9664.test.ts[14-19]
test/github-issues/9381/issue-9381.test.ts[56-61]
test/functional/find-options/array-contains-operator/array-contains-operator.test.ts[15-18]

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 `JsonContains` operator documentation lacks a clear warning about database compatibility. Users on MySQL, SQL Server, Oracle, or other non-Postgres databases will encounter SQL syntax errors at runtime if they try to use this operator, as it uses Postgres-specific syntax (`::jsonb @&gt;`).

# Issue Context
The operator is implemented in QueryBuilder.ts with hardcoded Postgres syntax and no database type checking. Tests confirm it only works on PostgreSQL and CockroachDB. The current documentation only has a parenthetical &quot;(Postgres notation)&quot; comment in the SQL example, which is insufficient to warn users.

# Fix Focus Areas
- docs/docs/working-with-entity-manager/3-find-options.md[534-548]

Add a clear warning note before the `JsonContains` example stating:
&gt; **Note:** This operator is only supported on PostgreSQL and CockroachDB databases.

Alternatively, add an inline note after the operator name:
```markdown
- `JsonContains` (PostgreSQL/CockroachDB only)
```

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


Qodo Logo

@gioboa
gioboa requested review from G0maa, alumni and naorpeled January 26, 2026 10:07

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your help @lraveri
Can you address the qodo suggestion about the compatibility of this feature?

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

Copy link
Copy Markdown

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Impact
General
Fix PostgreSQL cast operator spacing

Remove the space before the ::jsonb cast operator in the SQL example to follow
standard PostgreSQL syntax.

docs/docs/working-with-entity-manager/3-find-options.md [546-548]

 ```sql
-SELECT * FROM "post" WHERE "metadata" ::jsonb @> '{"author":{"name":"John"}}'
+SELECT * FROM "post" WHERE "metadata"::jsonb @> '{"author":{"name":"John"}}'


- [ ] **Apply / Chat** <!-- /improve --apply_suggestion=0 -->


<details><summary>Suggestion importance[1-10]: 3</summary>

__

Why: The suggestion correctly identifies a stylistic issue in an SQL example within the documentation, proposing a change to use the more canonical syntax for the PostgreSQL cast operator.

</details></details></td><td align=center>Low

</td></tr>
<tr><td align="center" colspan="2">

- [ ] More <!-- /improve --more_suggestions=true -->

</td><td></td></tr></tbody></table>

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

Copy link
Copy Markdown

Persistent review updated to latest commit 6d4f931

@lraveri

lraveri commented Jan 26, 2026

Copy link
Copy Markdown
Contributor Author

Not 100% sure we should add the “(PostgreSQL/CockroachDB only)” note here, since other operators like arrayContains / arrayContainedBy don’t have a similar disclaimer in the docs.

Also, in the codebase there isn’t any dialect check: TypeORM will generate the SQL as-is, and it will simply fail at runtime if the underlying driver doesn’t support @> / <@ (or ::jsonb).

For consistency, maybe we should either:

  • add the same note to all operators relying on dialect-specific syntax, or
  • avoid adding it just for this example.

WDYT? @gioboa

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ok, I see. Let's keep the note for this one and we can create another PR to fill the missing gap.
Thanks for your help 👏

@mguida22
mguida22 merged commit f13a452 into typeorm:master Jan 27, 2026
9 checks passed
kranners pushed a commit to kranners/typeorm that referenced this pull request Mar 1, 2026
@pkuczynski pkuczynski added this to the 1.0 milestone Mar 8, 2026
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.

How to use JsonContains in FindOptions

5 participants