Skip to Content
🎉 Deeb v0.0.11 released! Install with Cargo: cargo add deeb 🎉
DocsQueries

Querying in Deeb

Deeb provides a flexible and expressive query system for interacting with your data. Queries are used in find, update, and delete operations to filter documents based on custom conditions.


Query Types

TypeDescription
eqEqual — Matches documents with a field equal to a value.
neNot Equal — Matches documents where the field is not equal.
likeLike — Performs substring or pattern matching.
gtGreater Than — Matches documents with a field greater than a value.
ltLess Than — Matches documents with a field less than a value.
gteGreater Than or Equal — Same as above, but inclusive.
lteLess Than or Equal — Same as above, but inclusive.
andCombines multiple queries; all must match.
orCombines multiple queries; at least one must match.
allMatches all documents.
associatedQueries across associated entities.

Query Enum Definition

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub enum Query { Eq(Key, Value), Ne(Key, Value), Like(Key, String), Lt(Key, Value), Lte(Key, Value), Gt(Key, Value), Gte(Key, Value), And(Vec<Query>), Or(Vec<Query>), Associated(Entity, Box<Query>), All, }

You can construct queries either directly using the enum, or through helper functions for ease and clarity.


Examples

Match All Documents

let query = Query::All; let query = Query::all(); // Helper method

Match by Field

let query = Query::eq("name", "oliver"); // Helper let query = Query::Eq("name".into(), json!("oliver")); // Raw

Compound Conditions

let query = Query::and(vec![ Query::eq("name", "John"), Query::eq("age", 30), Query::eq("city", "New York"), ]); let query = Query::or(vec![ Query::eq("status", "active"), Query::eq("admin", true), ]);

Like Conditions

The like operator in Deeb works similarly to SQL’s LIKE ‘%value%’. It performs a partial match, checking if the target string contains the given substring anywhere in its value.

Note: You do not include the percentage signs, %%.

Associated Entities

let query = Query::associated(comment, Query::eq("user_id", 1));

🧠 Learn more about how to use queries in context in the Collection Trait Guide or explore advanced scenarios in the Programmatic Usage Guide.

📚 For full API reference, check out the Deeb docs on docs.rs .

Last updated on