8000 fix: enable is and isnot operator on JSON by fendy3002 · Pull Request #11271 · nocodb/nocodb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: enable is and isnot operator on JSON #11271

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

Merged
merged 1 commit into from
May 3, 2025
Merged

Conversation

fendy3002
Copy link
Collaborator

Change Summary

fix: enable is and isnot operator on JSON

Change type

  • fix: (bug fix for the user, not a fix to a build script)

Copy link
Contributor
coderabbitai bot commented May 2, 2025
📝 Walkthrough

Walkthrough

The changes introduce new helper functions to encapsulate repeated logic for checking if JSON fields are null, empty objects, or empty arrays in three handler files. These helpers are used to refactor existing code for the blank and notblank operators. Additionally, new comparison operators, is and isnot, are implemented to interpret semantic string values such as 'blank', 'empty', 'notblank', and 'notempty', mapping them to the appropriate null or non-null checks. All modifications are internal to the filter logic of each handler class, with no changes to exported interfaces or class signatures.

Changes

File(s) Change Summary
.../json.general.handler.ts
.../json.mysql.handler.ts
.../json.pg.handler.ts
Introduced appendIsNull and appendIsNotNull helper functions to encapsulate repeated query logic for null/empty checks. Refactored blank and notblank operators to use these helpers. Added new is and isnot operators with nested logic to handle semantic string values (blank, empty, notblank, notempty) by invoking the appropriate helper functions. No changes to exported or public entities.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Handler (General/MySQL/PG)
    participant QueryBuilder

    Client->>Handler (filter): Request filter with operator (e.g., is, isnot, blank, notblank)
    alt Operator is "blank" or "notblank"
        Handler->>Handler: Call appendIsNull or appendIsNotNull
        Handler->>QueryBuilder: Add null/empty or not-null/not-empty condition
    else Operator is "is" or "isnot"
        Handler->>Handler: Switch on filter value (blank, empty, notblank, notempty)
        Handler->>Handler: Call appendIsNull or appendIsNotNull as appropriate
        Handler->>QueryBuilder: Add corresponding condition
    else Other operators
        Handler->>QueryBuilder: Apply existing logic
    end
    QueryBuilder-->>Handler: Query conditions updated
    Handler-->>Client: Filtered results
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/nocodb/src/db/field-handler/handlers/json/json.mysql.handler.ts (1)

110-138: Well-implemented is and isnot operators!

The implementation is consistent with the other handlers and properly handles the semantic string values.

One minor point to consider for all handlers: if invalid values are passed to these operators, they will silently do nothing. Consider either:

  1. Adding a default case to handle invalid values explicitly, or
  2. Adding validation in the verifyFilter method to ensure only supported values are used

This would improve error handling, but the current implementation is functional.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6bfc99d and 4487464.

📒 Files selected for processing (3)
  • packages/nocodb/src/db/field-handler/handlers/json/json.general.handler.ts (2 hunks)
  • packages/nocodb/src/db/field-handler/handlers/json/json.mysql.handler.ts (2 hunks)
  • packages/nocodb/src/db/field-handler/handlers/json/json.pg.handler.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: release-docker / buildx
  • GitHub Check: unit-tests-pg
  • GitHub Check: unit-tests
🔇 Additional comments (7)
packages/nocodb/src/db/field-handler/handlers/json/json.pg.handler.ts (2)

9-42: Well-structured helper functions for common operations!

Extracting these helper functions is a great improvement as it encapsulates the repeated logic for checking null/empty JSON fields. This promotes code reusability and readability while reducing duplication.


120-149: Good implementation of is and isnot operators!

The implementation handles semantic string values like 'blank', 'empty', 'notblank', and 'notempty' appropriately. The logic is consistent and properly reuses the helper functions.

Some suggestions for future enhancements:

  • Consider adding documentation for these operators to help users understand the supported values
  • It might be useful to handle invalid values with a default case in the nested switch statements
packages/nocodb/src/db/field-handler/handlers/json/json.general.handler.ts (3)

23-35: Good extraction of helper functions!

Nice job encapsulating repeated logic into helper functions. This improves code maintainability and readability.

Unlike the PostgreSQL handler where helpers are at module level, these are scoped to the filter method which is appropriate since they're only used there.


97-103: Good refactoring of blank operator!

Using the helper function makes the code more concise and readable.


105-133: Well-implemented is and isnot operators!

The implementation is consistent with the PostgreSQL handler and properly handles all semantic string values.

packages/nocodb/src/db/field-handler/handlers/json/json.mysql.handler.ts (2)

23-35: Good extraction of MySQL-specific helper functions!

These helper functions properly handle MySQL JSON syntax with JSON_UNQUOTE. The implementation correctly encapsulates the repeated logic for checking null and empty JSON fields.


102-108: Good refactoring of blank and notblank operators!

Using the helper functions makes the code more concise and readable.

Copy link
Contributor
github-actions bot commented May 2, 2025

Uffizzi Ephemeral Environment Deploying

☁️ https://app.uffizzi.com/github.com/nocodb/nocodb/pull/11271

⚙️ Updating now by workflow run 14797101331.

What is Uffizzi? Learn more!

@dstala dstala merged commit 3334e1e into develop May 3, 2025
19 of 23 checks passed
@dstala dstala deleted the nc-fix/json-is-operator branch May 3, 2025 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0