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

Feature request: Customizing the query #123

Closed
mikeconley12 opened this issue Oct 17, 2020 · 16 comments
Closed

Feature request: Customizing the query #123

mikeconley12 opened this issue Oct 17, 2020 · 16 comments

Comments

@mikeconley12
Copy link

It would be great to have an ability to customize the query. See the Knex service adapter docs for details

@dekelev
Copy link
Member

dekelev commented Oct 17, 2020 via email

@mikeconley12
Copy link
Author

Thanks for your answer! I will check the modifiers in a few days and close this issue or explain why it doesn't work.

@mikeconley12
Copy link
Author

Hi @dekelev ! I have a question.
How can I specify multiple modifiers with different arguments?

I need an equivalent to this:

const women = await Person.query()
  .modify('filterAge', 18)
  .modify('filterGender', 'female');

@dekelev
Copy link
Member

dekelev commented Oct 18, 2020 via email

@dekelev
Copy link
Member

dekelev commented Oct 18, 2020 via email

@mikeconley12
Copy link
Author

yes, I checked the docs. But I need different arguments for each modifier. Is it possible?

params.query.$modify = { "modifier1_fn_name": ["args1"], "modifier2_fn_name": ["args2"] };

@dekelev
Copy link
Member

dekelev commented Oct 18, 2020 via email

@dekelev
Copy link
Member

dekelev commented Oct 18, 2020 via email

@mikeconley12
Copy link
Author

Sorry, but I already checked this test file and I didn't find a solution.

For example, I see here multiple modifiers, but all the modifiers have the same arguments.

@dekelev
Copy link
Member

dekelev commented Oct 18, 2020 via email

@mikeconley12
Copy link
Author

and rest of items are args for that modifier

No, in your example, large is a modifier

large: (builder, hasCeo) => {

Also see Objection.js documentation. It says that the first argument is a modifier, and the rest are arguments passed to the modify function

@dekelev
Copy link
Member

dekelev commented Oct 19, 2020

Right, so I'll add support for JSON object as value for $modify and we'll be able to use it as you suggested and without a breaking-change:

{ "modifier1_fn_name": ["args1"], "modifier2_fn_name": ["args2"] }

It's also much more readable in my opinion, so it would also be my default value type for $modify.
I'll add examples to the docs once it's ready, but basically it's a low effort task, so I hope to release it later today.

@mikeconley12
Copy link
Author

It's awesome! Thank you! But will it be a JSON string? Or just a regular JS object?

@dekelev
Copy link
Member

dekelev commented Oct 19, 2020 via email

@dekelev
Copy link
Member

dekelev commented Oct 19, 2020

Released with v6.1.0

I've updated the $modify docs as well. enjoy!

@dekelev dekelev closed this as completed Oct 19, 2020
@mikeconley12
Copy link
Author

Great, thanks for your help!

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

2 participants