Skip to content
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

1103 Improve arrow function #1112

Merged
merged 29 commits into from
Oct 23, 2024
Merged

1103 Improve arrow function #1112

merged 29 commits into from
Oct 23, 2024

Conversation

dantownsend
Copy link
Member

Resolves #1103

@dantownsend dantownsend added the enhancement New feature or request label Oct 18, 2024
@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 85.48387% with 9 lines in your changes missing coverage. Please review.

Project coverage is 88.42%. Comparing base (e2fa8f8) to head (87f8411).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
piccolo/query/operators/json.py 84.84% 5 Missing ⚠️
piccolo/querystring.py 60.00% 4 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1112      +/-   ##
==========================================
- Coverage   88.45%   88.42%   -0.04%     
==========================================
  Files         116      117       +1     
  Lines        8611     8653      +42     
==========================================
+ Hits         7617     7651      +34     
- Misses        994     1002       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sinisaos
Copy link
Member

@dantownsend It seems that when we use the arrow function we need strings for queries (not booleans or other types). I think that makes sense because querystring uses strings. If we change the data type to string in these tests, everything passes.

def test_arrow_where(self):
    """
    Make sure the arrow function can be used within a WHERE clause.
    """
    RecordingStudio(
        name="Abbey Road", facilities='{"mixing_desk": true}'
    ).save().run_sync()

    self.assertEqual(
        RecordingStudio.count()
        .where(RecordingStudio.facilities.arrow("mixing_desk").eq("true")) # <-- here
        .run_sync(),
        1,
    )

    self.assertEqual(
        RecordingStudio.count()
        .where(RecordingStudio.facilities.arrow("mixing_desk").eq("false")) # <-- here
        .run_sync(),
        0,
    )

I also removed the load json test because the output(load_json=True) doesn't return a boolean after new changes.

I hope that makes sense.

@dantownsend
Copy link
Member Author

@sinisaos Thanks - you're right, the JSON values have to be strings.

Copy link
Member

@sinisaos sinisaos left a comment

Choose a reason for hiding this comment

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

@dantownsend I think this is a great enhancement 👍

@dantownsend
Copy link
Member Author

@sinisaos Thanks. I went a bit crazy on this in the end.

You can now go multiple levels deep, and traverse array elements within the JSON.

await RecordingStudio.select(
    RecordingStudio.facilities["a"]["b"][0]["c"]
)

@sinisaos
Copy link
Member

@dantownsend Wow! It's really amazing.

@dantownsend
Copy link
Member Author

@sinisaos Thanks. It turned into a bigger thing than I expected. But with this, we can potentially do better JSON filtering in Piccolo Admin.

@dantownsend dantownsend merged commit 85ead5a into master Oct 23, 2024
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Bug: Where clause with Postgres JSONB nested field
3 participants