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

Statically typed filters? #8

Open
8176135 opened this issue Jul 27, 2019 · 1 comment
Open

Statically typed filters? #8

8176135 opened this issue Jul 27, 2019 · 1 comment

Comments

@8176135
Copy link

8176135 commented Jul 27, 2019

Is it possible to write statically typed filters? (e.g. similar to what diesel has or something else), and if not, is there any plans for them?

Something like:

#[derive(Debug, Serialize, Deserialize, Doc, Clone)]
pub struct Example {
	#[serde(rename = "_id")]
	pub id: Uid<Example>,
	pub description: String,
}

...

let example_col: Collection<Example>  = shared.db.existing_collection();
let res: Example = example_col.find_one(Example::description.eq("abc"));
@H2CO3
Copy link
Owner

H2CO3 commented Jul 27, 2019

Hey there!

Unfortunately there's currently nothing like this in Avocado. However, this is certainly something I have thought about, except that I'm not sure how I would go about implementing it.

I'm guessing that a new derive macro could pre-generate helper types for most of the MongoDB DSL (i.e. query and update operators) based on top-level field names and types, but it might become tricky to refer to subfields.

I'd also really like to solve this problem because it would bring a whole new set of static guarantees to Avocado.

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