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

does this support jsonb search ? #41

Open
fatkhanfauzi opened this issue Jan 9, 2019 · 10 comments
Open

does this support jsonb search ? #41

fatkhanfauzi opened this issue Jan 9, 2019 · 10 comments

Comments

@fatkhanfauzi
Copy link

does this support jsonb search ?

@kibertoad
Copy link
Collaborator

Let me try writing a test for that; I think not yet, but it could.

@kibertoad
Copy link
Collaborator

Can you detail your use-case? That would make it easier to design a solution.

@fatkhanfauzi
Copy link
Author

thanks for your quick reply.

here is my use case:
i have a column named status with this value
{ "history": [ "initial", "submitted" ], "currentState": "submitted" }

then i want to search the data by status -> currentState.
thanks

@kibertoad
Copy link
Collaborator

@fatkhanfauzi What kind of GET query would you like to use for that?

@fatkhanfauzi
Copy link
Author

@kibertoad something like status[currentState]:eq or status[currentState]:like
i think that's the best one since we can't use dot (.) as it will be indicated as relationship.
thought ?

@afm-sayem
Copy link
Contributor

You can write your own filter using registerFilter. Here's the documentation: https://github.com/Vincit/objection-find/blob/master/API.md#registerfilterstring-function---findquerybuilder

Here is an example of a custom full-text-search(search) filter: https://github.com/afm-sayem/ground-zero/blob/master/components/filters/text-search.js

@fatkhanfauzi
Copy link
Author

@afm-sayem yep i know we can do that, thanks for your suggestion.
but could be great if this package supports the jsonb search.
as i mentioned above.

something like status[currentState]:eq or status[currentState]:like
i think that's the best one since we can't use dot (.) as it will be indicated as relationship.

@fatkhanfauzi
Copy link
Author

@afm-sayem @kibertoad or probably using status->>currentState same as what i've done at the moment in my custom filter.

module.exports = function(propertyRef, value, modelClass) {
  const column = propertyRef.propertyName.split('->>')[0];
  const jsonbKey = propertyRef.propertyName.split('->>')[1];

  return {
    method: 'whereRaw',
    args: [`${column} ->> '${jsonbKey}' = ?`, value.toLowerCase()],
  };
};

@MoJo2600
Copy link

Query for jsonb fields seems to be possible with @fatkhanfauzi filter. But is there a way to have the result ordered by an jsonb property?

@fatkhanfauzi
Copy link
Author

Query for jsonb fields seems to be possible with @fatkhanfauzi filter. But is there a way to have the result ordered by an jsonb property?

iirc, when I was working on the project that uses this package.
i added a monkey patch to build a necessary complex query based on the given params before the query execution.

however, apologize that I'm not on that project anymore.
but this could be a clue, good luck !!

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

No branches or pull requests

4 participants