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

Query trait and find options #2

Closed
max-frai opened this issue Jun 18, 2019 · 6 comments
Closed

Query trait and find options #2

max-frai opened this issue Jun 18, 2019 · 6 comments

Comments

@max-frai
Copy link

max-frai commented Jun 18, 2019

Hi! I found that in Query trait method options (https://docs.rs/avocado/0.3.3/avocado/ops/trait.Query.html#method.options) is static method (does not have access to data).
It's useful to access some inner data to configure, for example, count and limit. I need this for pagination query where that params are dynamic for options but the same for filtering.

@max-frai
Copy link
Author

And I found that it's not even possible to pass options directly to find_many, for example. It takes default options directly without ability to replace them.
We can override options only defining own query with Query trait, but, as I mentioned before, it's not possible to pass there dynamic information.

@H2CO3
Copy link
Owner

H2CO3 commented Jun 18, 2019

Hey there!

Good call, I'll look into this in a couple of days, hopefully tomorrow. I hope that all similar methods could be uniformly transformed into taking &self.

@H2CO3 H2CO3 closed this as completed in 09cdf0f Jun 19, 2019
@H2CO3
Copy link
Owner

H2CO3 commented Jun 19, 2019

@max-frai Added some &self parameters where it made sense. Can you please check (by pointing your Cargo.toml to the exact commit above ^^) that it is doing what you wanted?

@max-frai
Copy link
Author

Yes, exactly what I need. Now I can write something like:

    fn options(&self) -> FindOptions {
        FindOptions {
            skip: Some(self.count * self.page),
            limit: Some(self.count),
            ..Default::default()
        }
    }

Thank you! :)

@H2CO3
Copy link
Owner

H2CO3 commented Jun 19, 2019

No problem, I'll push a new version to crates.io in a moment.

@H2CO3
Copy link
Owner

H2CO3 commented Jun 19, 2019

@max-frai v0.4.0 published on crates.io.

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