diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index 75c3ecb77..5fe88c885 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -541,8 +541,7 @@ pub fn now() -> AsExprOf { diesel::dsl::now.into_sql::() } -pub type AsRecordOutput = dsl::AsExprOf::SqlType>>; - +/// Trait alias for a type that can be converted to an SQL tuple using `IntoSql::into_sql` pub trait AsRecord: Expression + AsExpression> where Self::SqlType: 'static, @@ -554,8 +553,25 @@ impl>> AsRecord for T { } +/// Output of `IntoSql::into_sql` for a type that implements `AsRecord` +pub type AsRecordOutput = dsl::AsExprOf::SqlType>>; + +/// Output of `t.on((l0, l1).into_sql().eq((r0, r1)))` type OnTupleEq = dsl::On, (R0, R1)>>; +/// Creates an `ON` clause for a table where a person ID and another column are used as the +/// primary key. Use with the `QueryDsl::left_join` method. +/// +/// This example modifies a query to make columns in `community_actions` available: +/// +/// ``` +/// community::table +/// .left_join(actions( +/// community_actions::table, +/// my_person_id, +/// community::id, +/// )) +/// ``` pub fn actions( actions_table: T, person_id: Option

, @@ -585,8 +601,7 @@ pub fn actions_alias( ) -> OnTupleEq, AliasedField, AliasedField, P, C> where Alias: QuerySource + Copy, - T: AliasSource + Default, - T::Target: Table, + T: AliasSource> + Default, K0: Column, K1: Column
, (AliasedField, AliasedField): AsRecord, @@ -606,34 +621,32 @@ where /// `table_name::table.filter(table_name::action_name.is_not_null())`. pub fn action_query(column: C) -> dsl::Filter> where - C: Column, - C::Table: Default + FilterDsl>, - C::SqlType: SingleValue, + C: Column>, SqlType: SingleValue>, { action_query_with_fn(column, |t| t) } +/// `find_action(table_name::action_name, key)` is the same as +/// `table_name::table.find(key).filter(table_name::action_name.is_not_null())`. pub fn find_action( column: C, key: K, ) -> dsl::Filter, dsl::IsNotNull> where - C: Column, - C::Table: Default + FindDsl, - dsl::Find: FilterDsl>, - C::SqlType: SingleValue, + C: + Column>>, SqlType: SingleValue>, { action_query_with_fn(column, |t| t.find(key)) } +/// `action_query_with_fn(table_name::action_name, f)` is the same as +/// `f(table_name::table).filter(table_name::action_name.is_not_null())`. fn action_query_with_fn( column: C, f: impl FnOnce(C::Table) -> Q, ) -> dsl::Filter> where - C: Column, - C::Table: Default, - C::SqlType: SingleValue, + C: Column, Q: FilterDsl>, { f(C::Table::default()).filter(column.is_not_null())