pub struct QueryBuilder<'a> { /* private fields */ }Expand description
Builder for creating and executing document queries.
QueryBuilder uses a fluent interface pattern to construct and execute queries against Aurora collections.
§Examples
// Query for active premium users
let premium_users = db.query("users")
.filter(|f| f.eq("status", "active") && f.eq("account_type", "premium"))
.order_by("created_at", false)
.limit(10)
.collect()
.await?;Implementations§
Source§impl<'a> QueryBuilder<'a>
impl<'a> QueryBuilder<'a>
Sourcepub fn filter<F>(self, filter_fn: F) -> Self
pub fn filter<F>(self, filter_fn: F) -> Self
Add a filter function to the query
§Examples
let active_users = db.query("users")
.filter(|f| f.eq("status", "active"))
.collect()
.await?;Sourcepub fn offset(self, offset: usize) -> Self
pub fn offset(self, offset: usize) -> Self
Skip a number of results (for pagination)
§Examples
// For pagination: skip the first 20 results and get the next 10
.offset(20).limit(10)Sourcepub fn select(self, fields: &[&str]) -> Self
pub fn select(self, fields: &[&str]) -> Self
Select only specific fields to return
§Examples
// Only return name and email fields
.select(&["name", "email"])Sourcepub async fn watch(self) -> Result<QueryWatcher>where
'a: 'static,
pub async fn watch(self) -> Result<QueryWatcher>where
'a: 'static,
Watch the query for real-time updates
Returns a QueryWatcher that emits updates when documents are added, removed, or modified in ways that affect the query results.
Note: This method requires the QueryBuilder to have a ’static lifetime,
which means the database reference must also be ’static (e.g., Arc
§Examples
let mut watcher = db.query("users")
.filter(|f| f.eq("active", true))
.watch()
.await?;
// Receive updates in real-time
while let Some(update) = watcher.next().await {
match update {
QueryUpdate::Added(doc) => println!("New: {:?}", doc),
QueryUpdate::Removed(doc) => println!("Removed: {:?}", doc),
QueryUpdate::Modified { old, new } => println!("Modified: {:?}", new),
}
}Sourcepub async fn first_one(self) -> Result<Option<Document>>
pub async fn first_one(self) -> Result<Option<Document>>
Get only the first matching document or None if no matches
§Examples
let user = db.query("users")
.filter(|f| f.eq("email", "jane@example.com"))
.first_one()
.await?;Sourcepub async fn count(self) -> Result<usize>
pub async fn count(self) -> Result<usize>
Count the number of documents matching the query
§Examples
let active_count = db.query("users")
.filter(|f| f.eq("status", "active"))
.count()
.await?;Sourcepub async fn update(self, updates: HashMap<&str, Value>) -> Result<usize>
pub async fn update(self, updates: HashMap<&str, Value>) -> Result<usize>
Update documents matching the query with new field values
§Returns
The number of documents updated
§Examples
let updated = db.query("products")
.filter(|f| f.lt("stock", 5))
.update([
("status", Value::String("low_stock".to_string())),
("needs_reorder", Value::Bool(true))
].into_iter().collect())
.await?;