H2CO3 / avocado

Strongly-typed MongoDB driver for Rust
MIT License
81 stars 2 forks source link

Query trait and find options #2

Closed max-frai closed 5 years ago

max-frai commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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

H2CO3 commented 5 years ago

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