pub struct QueryBuilder { /* private fields */ }
Expand description
Query builder for SELECT operations
Implementations§
Source§impl QueryBuilder
impl QueryBuilder
Sourcepub fn order(self, column: &str, direction: OrderDirection) -> Self
pub fn order(self, column: &str, direction: OrderDirection) -> Self
Add ordering
Sourcepub fn and<F>(self, builder_fn: F) -> Self
pub fn and<F>(self, builder_fn: F) -> Self
Group filters with AND logic
§Examples
let client = Client::new("http://localhost:54321", "test-key").unwrap();
// Find users where age >= 18 AND status = "active" AND city = "NYC"
let adults_in_nyc: Vec<Value> = client.database()
.from("users")
.select("*")
.and(|query| {
query
.gte("age", "18")
.eq("status", "active")
.eq("city", "NYC")
})
.execute()
.await
.unwrap();
Sourcepub fn or<F>(self, builder_fn: F) -> Self
pub fn or<F>(self, builder_fn: F) -> Self
Group filters with OR logic
§Examples
let client = Client::new("http://localhost:54321", "test-key").unwrap();
// Find users where status = "online" OR status = "away"
let active_users: Vec<Value> = client.database()
.from("users")
.select("*")
.or(|query| {
query
.eq("status", "online")
.eq("status", "away")
})
.execute()
.await
.unwrap();
Sourcepub fn not<F>(self, builder_fn: F) -> Self
pub fn not<F>(self, builder_fn: F) -> Self
Apply NOT logic to a filter
§Examples
let client = Client::new("http://localhost:54321", "test-key").unwrap();
// Find users where NOT (status = "banned")
let active_users: Vec<Value> = client.database()
.from("users")
.select("*")
.not(|query| query.eq("status", "banned"))
.execute()
.await
.unwrap();
Sourcepub fn inner_join(self, foreign_table: &str, foreign_columns: &str) -> Self
pub fn inner_join(self, foreign_table: &str, foreign_columns: &str) -> Self
Add an INNER JOIN to another table
§Examples
let client = Client::new("http://localhost:54321", "test-key").unwrap();
// Join posts with authors: SELECT posts.*, authors.name, authors.email
let posts_with_authors: Vec<Value> = client.database()
.from("posts")
.select("*")
.inner_join("authors", "name,email")
.execute()
.await
.unwrap();
Sourcepub fn left_join(self, foreign_table: &str, foreign_columns: &str) -> Self
pub fn left_join(self, foreign_table: &str, foreign_columns: &str) -> Self
Add a LEFT JOIN to another table
§Examples
let client = Client::new("http://localhost:54321", "test-key").unwrap();
// Left join posts with optional authors
let posts_with_optional_authors: Vec<Value> = client.database()
.from("posts")
.select("*")
.left_join("authors", "name,email")
.execute()
.await
.unwrap();
Sourcepub fn inner_join_as(
self,
foreign_table: &str,
foreign_columns: &str,
alias: &str,
) -> Self
pub fn inner_join_as( self, foreign_table: &str, foreign_columns: &str, alias: &str, ) -> Self
Add an INNER JOIN with a custom alias
§Examples
let client = Client::new("http://localhost:54321", "test-key").unwrap();
// Join with alias: SELECT posts.*, author:authors!inner(name,email)
let posts: Vec<Value> = client.database()
.from("posts")
.select("*")
.inner_join_as("authors", "name,email", "author")
.execute()
.await
.unwrap();
Sourcepub fn left_join_as(
self,
foreign_table: &str,
foreign_columns: &str,
alias: &str,
) -> Self
pub fn left_join_as( self, foreign_table: &str, foreign_columns: &str, alias: &str, ) -> Self
Add a LEFT JOIN with a custom alias
§Examples
let client = Client::new("http://localhost:54321", "test-key").unwrap();
// Left join with alias: SELECT posts.*, author:authors(name,email)
let posts: Vec<Value> = client.database()
.from("posts")
.select("*")
.left_join_as("authors", "name,email", "author")
.execute()
.await
.unwrap();
Sourcepub async fn execute<T>(&self) -> Result<Vec<T>>where
T: for<'de> Deserialize<'de>,
pub async fn execute<T>(&self) -> Result<Vec<T>>where
T: for<'de> Deserialize<'de>,
Execute the query
Sourcepub async fn single_execute<T>(&self) -> Result<Option<T>>where
T: for<'de> Deserialize<'de>,
pub async fn single_execute<T>(&self) -> Result<Option<T>>where
T: for<'de> Deserialize<'de>,
Execute the query and return a single row
Trait Implementations§
Source§impl Clone for QueryBuilder
impl Clone for QueryBuilder
Source§fn clone(&self) -> QueryBuilder
fn clone(&self) -> QueryBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for QueryBuilder
impl !RefUnwindSafe for QueryBuilder
impl Send for QueryBuilder
impl Sync for QueryBuilder
impl Unpin for QueryBuilder
impl !UnwindSafe for QueryBuilder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more