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 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?;Auto Trait Implementations§
impl<'a> Freeze for QueryBuilder<'a>
impl<'a> !RefUnwindSafe for QueryBuilder<'a>
impl<'a> Send for QueryBuilder<'a>
impl<'a> !Sync for QueryBuilder<'a>
impl<'a> Unpin for QueryBuilder<'a>
impl<'a> !UnwindSafe for QueryBuilder<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more