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

Support equality predicates between jsonb nodes #240

Merged
merged 5 commits into from
May 30, 2018
Merged

Conversation

shioyama
Copy link
Owner

@shioyama shioyama commented May 30, 2018

Previously it was not possible to create equality predicates between jsonb nodes. This fixes the issue, so you can do:

Post.i18n { title.eq(content) }

... and Mobility will return all posts whose title and content are the same, for Jsonb (and Container) backends (already worked for other backends). I think this is the last issue to fix before releasing 0.7.0 🎉

Rather than handle equality in the PostgreSQL visitor, it's easier to do
it in the node itself. This allows us to support a.eq(b) where both a
and b are jsonb nodes, which previously would raise a stack error
exception when Mobility attempted to convert b to JSON.
when NilClass
to_question.not
when Integer, Array, Hash
to_dash_arrow.eq(other.to_json)
Copy link
Owner Author

Choose a reason for hiding this comment

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

Previously Jsonb used the default -> operator, but this is problematic in general, so instead we now use ->> which returns a string and does not require casting. In case we are calling eq with an argument that is an integer, array or hash, we convert the argument to json and compare using -> as before.

Non-string translations are an edge case, but one that I want to support.

@shioyama shioyama merged commit 553bf53 into master May 30, 2018
@shioyama shioyama deleted the jsonb_equality branch May 30, 2018 02:43
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.

1 participant