pub struct Relation<T: Record> { /* private fields */ }Expand description
A chainable query builder for Record types.
Implementations§
Source§impl<T: Record> Relation<T>
impl<T: Record> Relation<T>
Sourcepub fn where(self, conditions: HashMap<String, JsonValue>) -> Self
pub fn where(self, conditions: HashMap<String, JsonValue>) -> Self
Adds equality conditions to the relation.
Sourcepub fn order(self, column: &str, dir: OrderDirection) -> Self
pub fn order(self, column: &str, dir: OrderDirection) -> Self
Adds an order clause to the relation.
Sourcepub fn select_columns(self, columns: &[&str]) -> Self
pub fn select_columns(self, columns: &[&str]) -> Self
Restricts which columns are selected.
Sourcepub fn select(self, columns: &[&str]) -> Self
pub fn select(self, columns: &[&str]) -> Self
Backwards-compatible alias for Self::select_columns.
Sourcepub fn joins(self, association: &str) -> Self
pub fn joins(self, association: &str) -> Self
Stores a join declaration (implementation pending full association support).
Sourcepub fn includes(self, association: &str) -> Self
pub fn includes(self, association: &str) -> Self
Stores an eager-load declaration (implementation pending).
Sourcepub fn reorder(self, column: &str, dir: OrderDirection) -> Self
pub fn reorder(self, column: &str, dir: OrderDirection) -> Self
Replaces the current ordering.
Sourcepub fn rewhere(self, conditions: HashMap<String, JsonValue>) -> Self
pub fn rewhere(self, conditions: HashMap<String, JsonValue>) -> Self
Replaces the current where scope.
Sourcepub fn not_where(self, conditions: HashMap<String, JsonValue>) -> Self
pub fn not_where(self, conditions: HashMap<String, JsonValue>) -> Self
Adds negated equality conditions to the relation.
Sourcepub fn not(self, conditions: HashMap<String, JsonValue>) -> Self
pub fn not(self, conditions: HashMap<String, JsonValue>) -> Self
Backwards-compatible alias for Self::not_where.
Sourcepub fn or_where(self, conditions: HashMap<String, JsonValue>) -> Self
pub fn or_where(self, conditions: HashMap<String, JsonValue>) -> Self
Combines an additional where scope with OR semantics.
Sourcepub async fn load(&self, db: &DatabaseConnection) -> Result<Vec<T>, RecordError>
pub async fn load(&self, db: &DatabaseConnection) -> Result<Vec<T>, RecordError>
Executes the relation and returns all matching records.
Sourcepub fn load_sync(&self) -> Result<Vec<T>, RecordError>
pub fn load_sync(&self) -> Result<Vec<T>, RecordError>
Synchronous wrapper for Self::load.
Sourcepub async fn find_each<F>(
&self,
batch_size: u64,
db: &DatabaseConnection,
f: F,
) -> Result<(), RecordError>
pub async fn find_each<F>( &self, batch_size: u64, db: &DatabaseConnection, f: F, ) -> Result<(), RecordError>
Iterates over records in batches, calling the closure for each record.
Sourcepub fn find_each_sync<F>(
&self,
batch_size: u64,
f: F,
) -> Result<(), RecordError>
pub fn find_each_sync<F>( &self, batch_size: u64, f: F, ) -> Result<(), RecordError>
Synchronous wrapper for Self::find_each.
Sourcepub async fn find_in_batches<F>(
&self,
batch_size: u64,
db: &DatabaseConnection,
f: F,
) -> Result<(), RecordError>
pub async fn find_in_batches<F>( &self, batch_size: u64, db: &DatabaseConnection, f: F, ) -> Result<(), RecordError>
Iterates over matching records in batches, calling the closure for each batch.
Sourcepub fn find_in_batches_sync<F>(
&self,
batch_size: u64,
f: F,
) -> Result<(), RecordError>
pub fn find_in_batches_sync<F>( &self, batch_size: u64, f: F, ) -> Result<(), RecordError>
Synchronous wrapper for Self::find_in_batches.
Sourcepub async fn first(
&self,
db: &DatabaseConnection,
) -> Result<Option<T>, RecordError>
pub async fn first( &self, db: &DatabaseConnection, ) -> Result<Option<T>, RecordError>
Executes the relation and returns the first matching record.
Sourcepub fn first_sync(&self) -> Result<Option<T>, RecordError>
pub fn first_sync(&self) -> Result<Option<T>, RecordError>
Synchronous wrapper for Self::first.
Sourcepub async fn last(
&self,
db: &DatabaseConnection,
) -> Result<Option<T>, RecordError>
pub async fn last( &self, db: &DatabaseConnection, ) -> Result<Option<T>, RecordError>
Executes the relation and returns the last matching record within the current scope.
Sourcepub fn last_sync(&self) -> Result<Option<T>, RecordError>
pub fn last_sync(&self) -> Result<Option<T>, RecordError>
Synchronous wrapper for Self::last.
Sourcepub async fn count(&self, db: &DatabaseConnection) -> Result<u64, RecordError>where
<T::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
<T::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync,
pub async fn count(&self, db: &DatabaseConnection) -> Result<u64, RecordError>where
<T::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
<T::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync,
Counts matching rows.
Sourcepub fn count_sync(&self) -> Result<u64, RecordError>where
<T::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
<T::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync,
pub fn count_sync(&self) -> Result<u64, RecordError>where
<T::Entity as EntityTrait>::Column: ColumnTrait + Iterable,
<T::Entity as EntityTrait>::Model: FromQueryResult + Send + Sync,
Synchronous wrapper for Self::count.
Sourcepub async fn exists(&self, db: &DatabaseConnection) -> Result<bool, RecordError>
pub async fn exists(&self, db: &DatabaseConnection) -> Result<bool, RecordError>
Returns true when the relation matches at least one row.
Sourcepub fn exists_sync(&self) -> Result<bool, RecordError>
pub fn exists_sync(&self) -> Result<bool, RecordError>
Synchronous wrapper for Self::exists.
Sourcepub async fn sole(&self, db: &DatabaseConnection) -> Result<T, RecordError>
pub async fn sole(&self, db: &DatabaseConnection) -> Result<T, RecordError>
Returns the only matching record.
Sourcepub fn sole_sync(&self) -> Result<T, RecordError>
pub fn sole_sync(&self) -> Result<T, RecordError>
Synchronous wrapper for Self::sole.
Sourcepub async fn explain(
&self,
db: &DatabaseConnection,
) -> Result<String, RecordError>
pub async fn explain( &self, db: &DatabaseConnection, ) -> Result<String, RecordError>
Returns the database query plan as a string.
Sourcepub fn explain_sync(&self) -> Result<String, RecordError>
pub fn explain_sync(&self) -> Result<String, RecordError>
Synchronous wrapper for Self::explain.
Sourcepub async fn sum(
&self,
column: &str,
db: &DatabaseConnection,
) -> Result<f64, RecordError>
pub async fn sum( &self, column: &str, db: &DatabaseConnection, ) -> Result<f64, RecordError>
Returns the sum of the specified column.
Sourcepub fn sum_sync(&self, column: &str) -> Result<f64, RecordError>
pub fn sum_sync(&self, column: &str) -> Result<f64, RecordError>
Synchronous wrapper for Self::sum.
Sourcepub async fn average(
&self,
column: &str,
db: &DatabaseConnection,
) -> Result<f64, RecordError>
pub async fn average( &self, column: &str, db: &DatabaseConnection, ) -> Result<f64, RecordError>
Returns the average of the specified column.
Sourcepub fn average_sync(&self, column: &str) -> Result<f64, RecordError>
pub fn average_sync(&self, column: &str) -> Result<f64, RecordError>
Synchronous wrapper for Self::average.
Sourcepub async fn minimum(
&self,
column: &str,
db: &DatabaseConnection,
) -> Result<Option<JsonValue>, RecordError>
pub async fn minimum( &self, column: &str, db: &DatabaseConnection, ) -> Result<Option<JsonValue>, RecordError>
Returns the minimum value of the specified column.
Sourcepub fn minimum_sync(
&self,
column: &str,
) -> Result<Option<JsonValue>, RecordError>
pub fn minimum_sync( &self, column: &str, ) -> Result<Option<JsonValue>, RecordError>
Synchronous wrapper for Self::minimum.
Sourcepub async fn maximum(
&self,
column: &str,
db: &DatabaseConnection,
) -> Result<Option<JsonValue>, RecordError>
pub async fn maximum( &self, column: &str, db: &DatabaseConnection, ) -> Result<Option<JsonValue>, RecordError>
Returns the maximum value of the specified column.
Sourcepub fn maximum_sync(
&self,
column: &str,
) -> Result<Option<JsonValue>, RecordError>
pub fn maximum_sync( &self, column: &str, ) -> Result<Option<JsonValue>, RecordError>
Synchronous wrapper for Self::maximum.
Sourcepub async fn group_count(
&self,
db: &DatabaseConnection,
) -> Result<HashMap<JsonValue, JsonValue>, RecordError>
pub async fn group_count( &self, db: &DatabaseConnection, ) -> Result<HashMap<JsonValue, JsonValue>, RecordError>
Returns grouped counts for the first configured group column.
Sourcepub async fn group_sum(
&self,
column: &str,
db: &DatabaseConnection,
) -> Result<HashMap<JsonValue, JsonValue>, RecordError>
pub async fn group_sum( &self, column: &str, db: &DatabaseConnection, ) -> Result<HashMap<JsonValue, JsonValue>, RecordError>
Returns grouped sums for the first configured group column.
Sourcepub async fn group_average(
&self,
column: &str,
db: &DatabaseConnection,
) -> Result<HashMap<JsonValue, JsonValue>, RecordError>
pub async fn group_average( &self, column: &str, db: &DatabaseConnection, ) -> Result<HashMap<JsonValue, JsonValue>, RecordError>
Returns grouped averages for the first configured group column.
Sourcepub async fn group_minimum(
&self,
column: &str,
db: &DatabaseConnection,
) -> Result<HashMap<JsonValue, JsonValue>, RecordError>
pub async fn group_minimum( &self, column: &str, db: &DatabaseConnection, ) -> Result<HashMap<JsonValue, JsonValue>, RecordError>
Returns grouped minimum values for the first configured group column.
Sourcepub async fn group_maximum(
&self,
column: &str,
db: &DatabaseConnection,
) -> Result<HashMap<JsonValue, JsonValue>, RecordError>
pub async fn group_maximum( &self, column: &str, db: &DatabaseConnection, ) -> Result<HashMap<JsonValue, JsonValue>, RecordError>
Returns grouped maximum values for the first configured group column.
Sourcepub async fn pluck_columns(
&self,
columns: &[&str],
db: &DatabaseConnection,
) -> Result<Vec<Vec<JsonValue>>, RecordError>
pub async fn pluck_columns( &self, columns: &[&str], db: &DatabaseConnection, ) -> Result<Vec<Vec<JsonValue>>, RecordError>
Plucks the values of the specified columns into row vectors.
Sourcepub fn pluck_columns_sync(
&self,
columns: &[&str],
) -> Result<Vec<Vec<JsonValue>>, RecordError>
pub fn pluck_columns_sync( &self, columns: &[&str], ) -> Result<Vec<Vec<JsonValue>>, RecordError>
Synchronous wrapper for Self::pluck_columns.
Sourcepub async fn pluck(
&self,
column: &str,
db: &DatabaseConnection,
) -> Result<Vec<JsonValue>, RecordError>
pub async fn pluck( &self, column: &str, db: &DatabaseConnection, ) -> Result<Vec<JsonValue>, RecordError>
Plucks the values of the specified column into a Vec.
Sourcepub fn pluck_sync(&self, column: &str) -> Result<Vec<JsonValue>, RecordError>
pub fn pluck_sync(&self, column: &str) -> Result<Vec<JsonValue>, RecordError>
Synchronous wrapper for Self::pluck.
Sourcepub async fn pick(
&self,
column: &str,
db: &DatabaseConnection,
) -> Result<Option<JsonValue>, RecordError>
pub async fn pick( &self, column: &str, db: &DatabaseConnection, ) -> Result<Option<JsonValue>, RecordError>
Returns the first value of the specified column.
Sourcepub fn pick_sync(&self, column: &str) -> Result<Option<JsonValue>, RecordError>
pub fn pick_sync(&self, column: &str) -> Result<Option<JsonValue>, RecordError>
Synchronous wrapper for Self::pick.
Sourcepub async fn ids(
&self,
db: &DatabaseConnection,
) -> Result<Vec<i64>, RecordError>
pub async fn ids( &self, db: &DatabaseConnection, ) -> Result<Vec<i64>, RecordError>
Returns all primary key values.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Relation<T>
impl<T> RefUnwindSafe for Relation<T>where
T: RefUnwindSafe,
impl<T> Send for Relation<T>
impl<T> Sync for Relation<T>
impl<T> Unpin for Relation<T>where
T: Unpin,
impl<T> UnsafeUnpin for Relation<T>
impl<T> UnwindSafe for Relation<T>where
T: UnwindSafe,
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
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>
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>
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