From 0b3b2004cb9db2d017f4b94119200424e78379b8 Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Tue, 3 Sep 2024 14:27:02 -0400 Subject: [PATCH 1/3] make InsertOrIgnore + Replace public for 3rd party backend --- diesel/src/query_builder/insert_statement/mod.rs | 3 +++ diesel/src/query_builder/mod.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/diesel/src/query_builder/insert_statement/mod.rs b/diesel/src/query_builder/insert_statement/mod.rs index a8e0ca566377..c8289178bc5d 100644 --- a/diesel/src/query_builder/insert_statement/mod.rs +++ b/diesel/src/query_builder/insert_statement/mod.rs @@ -5,6 +5,9 @@ mod insert_from_select; pub(crate) use self::batch_insert::BatchInsert; pub(crate) use self::column_list::ColumnList; pub(crate) use self::insert_from_select::InsertFromSelect; +#[diesel_derives::__diesel_public_if( + feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes" +)] pub(crate) use self::private::{Insert, InsertOrIgnore, Replace}; use super::returning_clause::*; diff --git a/diesel/src/query_builder/mod.rs b/diesel/src/query_builder/mod.rs index f1e62074bfba..509f5750a6f8 100644 --- a/diesel/src/query_builder/mod.rs +++ b/diesel/src/query_builder/mod.rs @@ -83,7 +83,7 @@ pub(crate) use self::insert_statement::{UndecoratedInsertRecord, ValuesClause}; #[cfg(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes")] #[doc(inline)] -pub use self::insert_statement::DefaultValues; +pub use self::insert_statement::{DefaultValues, InsertOrIgnore, Replace}; #[cfg(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes")] #[doc(inline)] From 019e44f842f54acfb44a2cbc9c410a2db23e7874 Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Wed, 4 Sep 2024 13:38:52 -0400 Subject: [PATCH 2/3] make items in combination_clause public for third-party backends - `SupportsCombinationClause` - All, Distinct, Except, intersect, ParenthesisWrapper, Union --- diesel/src/query_builder/combination_clause.rs | 16 ++++++++++++---- diesel/src/query_builder/mod.rs | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/diesel/src/query_builder/combination_clause.rs b/diesel/src/query_builder/combination_clause.rs index f97046509df5..45ccab8184f7 100644 --- a/diesel/src/query_builder/combination_clause.rs +++ b/diesel/src/query_builder/combination_clause.rs @@ -357,7 +357,15 @@ pub trait SupportsCombinationClause {} #[derive(Debug, Copy, Clone, QueryId)] /// Wrapper used to wrap rhs sql in parenthesis when supported by backend -pub struct ParenthesisWrapper(T); +#[diesel_derives::__diesel_public_if( + feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes", + public_fields(inner) +)] +pub struct ParenthesisWrapper { + /// the inner parenthesis definition + #[allow(dead_code)] + inner: T, +} #[cfg(feature = "postgres_backend")] mod postgres { @@ -367,7 +375,7 @@ mod postgres { impl> QueryFragment for ParenthesisWrapper { fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> { out.push_sql("("); - self.0.walk_ast(out.reborrow())?; + self.inner.walk_ast(out.reborrow())?; out.push_sql(")"); Ok(()) } @@ -389,7 +397,7 @@ mod mysql { impl> QueryFragment for ParenthesisWrapper { fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Mysql>) -> QueryResult<()> { out.push_sql("("); - self.0.walk_ast(out.reborrow())?; + self.inner.walk_ast(out.reborrow())?; out.push_sql(")"); Ok(()) } @@ -410,7 +418,7 @@ mod sqlite { // we can emulate this by construct a fake outer // SELECT * FROM (inner_query) statement out.push_sql("SELECT * FROM ("); - self.0.walk_ast(out.reborrow())?; + self.inner.walk_ast(out.reborrow())?; out.push_sql(")"); Ok(()) } diff --git a/diesel/src/query_builder/mod.rs b/diesel/src/query_builder/mod.rs index 509f5750a6f8..24f4c33a1c38 100644 --- a/diesel/src/query_builder/mod.rs +++ b/diesel/src/query_builder/mod.rs @@ -64,6 +64,10 @@ pub use self::update_statement::target::{IntoUpdateTarget, UpdateTarget}; #[doc(inline)] pub use self::update_statement::{BoxedUpdateStatement, UpdateStatement}; +#[cfg(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes")] +pub use self::combination_clause::{ + All, Distinct, Except, Intersect, ParenthesisWrapper, SupportsCombinationClause, Union, +}; #[cfg(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes")] pub use self::limit_clause::{LimitClause, NoLimitClause}; #[cfg(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes")] From a186318e610dd3f6fe331d30e0abcd16b180ed1a Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Mon, 7 Oct 2024 13:00:56 -0400 Subject: [PATCH 3/3] fix compilation tests --- .../src/query_builder/combination_clause.rs | 4 +- diesel_compile_tests/Cargo.lock | 257 +++++++++--------- .../tests/fail/alias_and_group_by.stderr | 3 +- ...ectable_if_inner_expr_is_selectable.stderr | 12 +- ...ay_expressions_must_be_correct_type.stderr | 36 +-- ...array_expressions_must_be_same_type.stderr | 108 +++----- .../fail/array_only_usable_with_pg.stderr | 6 +- .../fail/boxed_queries_and_group_by.stderr | 11 +- ...re_selectable_expression_for_filter.stderr | 3 +- ...t_load_default_select_with_group_by.stderr | 6 +- ...aggregate_and_non_aggregate_selects.stderr | 8 +- .../cannot_pass_aggregate_to_where.stderr | 3 +- ...th_methods_other_than_filter_called.stderr | 10 +- .../columns_cannot_be_rhs_of_insert.stderr | 6 +- ...tom_returning_requires_nonaggregate.stderr | 6 +- ...ning_requires_selectable_expression.stderr | 9 +- ...support_returning_methods_on_sqlite.stderr | 12 +- .../tests/fail/derive/aliases.stderr | 49 ++-- ...nct_on_clause_only_supported_for_pg.stderr | 16 +- ...t_on_requires_matching_order_clause.stderr | 30 +- ...ison_for_columns_from_another_table.stderr | 28 +- ...quires_bool_nonaggregate_expression.stderr | 3 +- ...aving_cant_be_used_without_group_by.stderr | 9 +- .../fail/ilike_only_compiles_for_pg.stderr | 16 +- ..._reference_columns_from_other_table.stderr | 14 +- ..._cant_be_used_with_tuples_or_arrays.stderr | 6 +- ...m_select_requires_valid_column_list.stderr | 8 +- ...here_clause_not_supported_on_sqlite.stderr | 13 +- ...pdate_where_not_supported_on_sqlite.stderr | 8 +- ...support_returning_methods_on_sqlite.stderr | 12 +- .../tests/fail/invalid_group_by.stderr | 12 +- .../tests/fail/invalid_joins.stderr | 106 +++----- ...n_requires_valid_boolean_expression.stderr | 3 +- ...es_not_support_offset_without_limit.stderr | 14 +- .../tests/fail/mysql_on_conflict_tests.stderr | 89 +++--- .../tests/fail/only_only_on_table.stderr | 3 +- ...ary_expressions_only_usable_with_pg.stderr | 12 +- ...ions_cant_be_used_in_a_sqlite_query.stderr | 27 +- ...ert_do_update_requires_valid_update.stderr | 3 +- .../returning_cannot_be_called_twice.stderr | 12 +- ...ause_requires_selectable_expression.stderr | 6 +- ...side_of_left_join_requires_nullable.stderr | 60 ++-- ...e_cannot_be_mixed_with_some_clauses.stderr | 159 +++++------ ...for_update_cannot_be_used_on_sqlite.stderr | 12 +- ...te_no_wait_cannot_be_used_on_sqlite.stderr | 16 +- ...kip_locked_cannot_be_used_on_sqlite.stderr | 16 +- .../select_requires_valid_grouping.stderr | 27 +- .../tests/fail/selectable.stderr | 126 +++------ .../fail/selectable_with_typemisamatch.stderr | 3 +- ...sert_or_ignore_cannot_be_used_on_pg.stderr | 6 +- .../sqlite_upsert_cannot_be_used_on_pg.stderr | 6 +- ...lect_cannot_reference_random_tables.stderr | 51 ++-- .../subselect_requires_correct_type.stderr | 2 +- .../update_requires_valid_where_clause.stderr | 13 +- ...support_returning_methods_on_sqlite.stderr | 12 +- ...iple_values_not_supported_on_sqlite.stderr | 24 +- ...nctions_follow_same_selection_rules.stderr | 9 +- ...alid_grouping_and_boxed_expressions.stderr | 21 +- 58 files changed, 597 insertions(+), 965 deletions(-) diff --git a/diesel/src/query_builder/combination_clause.rs b/diesel/src/query_builder/combination_clause.rs index 45ccab8184f7..784b1c0db3bc 100644 --- a/diesel/src/query_builder/combination_clause.rs +++ b/diesel/src/query_builder/combination_clause.rs @@ -57,8 +57,8 @@ impl CombinationClause` = note: associated types for the current `impl` cannot be restricted in `where` clauses = note: 1 redundant requirement hidden = note: required for `AliasedField` to implement `ValidGrouping>` - = note: required for `SelectStatement>, DefaultSelectClause>, ..., ..., ..., ..., ...>` to implement `SelectDsl>` - = note: consider using `--verbose` to print the full type name to the console + = note: required for `SelectStatement>, diesel::query_builder::select_clause::DefaultSelectClause>>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::NoWhereClause, diesel::query_builder::order_clause::NoOrderClause, LimitOffsetClause, diesel::query_builder::group_by_clause::GroupByClause>>` to implement `SelectDsl>` diff --git a/diesel_compile_tests/tests/fail/any_is_only_selectable_if_inner_expr_is_selectable.stderr b/diesel_compile_tests/tests/fail/any_is_only_selectable_if_inner_expr_is_selectable.stderr index a4a43505b303..e5c7c3fb7a70 100644 --- a/diesel_compile_tests/tests/fail/any_is_only_selectable_if_inner_expr_is_selectable.stderr +++ b/diesel_compile_tests/tests/fail/any_is_only_selectable_if_inner_expr_is_selectable.stderr @@ -21,10 +21,10 @@ note: required for `more_stuff::columns::names` to implement `AppearsOnTable