Skip to content

Commit 838c6bc

Browse files
authored
Merge pull request diesel-rs#3195 from weiznich/make_more_things_private
Put the `backend::sql_dialect` module behind the
2 parents 48bea31 + 2db5464 commit 838c6bc

9 files changed

Lines changed: 132 additions & 63 deletions

diesel/src/backend.rs

Lines changed: 90 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ pub type BindCollector<'a, DB> = <DB as HasBindCollector<'a>>::BindCollector;
142142
/// a custom `QueryFragment<YourBackend, YourSpecialSyntaxType>` implementation
143143
/// to specialize on generic `QueryFragment<DB, DB::AssociatedType>` implementations.
144144
///
145-
/// See the [`sql_dialect`] module for options provided by diesel out of the box.
145+
#[cfg_attr(
146+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes",
147+
doc = "See the [`sql_dialect`] module for options provided by diesel out of the box."
148+
)]
146149
pub trait SqlDialect: self::private::TrustedBackend {
147150
/// Configures how this backends supports `RETURNING` clauses
148151
///
@@ -157,21 +160,30 @@ pub trait SqlDialect: self::private::TrustedBackend {
157160
doc = "implementation for `ReturningClause`"
158161
)]
159162
///
160-
/// See [`sql_dialect::returning_clause`] for provided default implementations
163+
#[cfg_attr(
164+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes",
165+
doc = "See [`sql_dialect::returning_clause`] for provided default implementations"
166+
)]
161167
type ReturningClause;
162168
/// Configures how this backend supports `ON CONFLICT` clauses
163169
///
164170
/// This allows backends to opt in `ON CONFLICT` clause support
165171
///
166-
/// See [`sql_dialect::on_conflict_clause`] for provided default implementations
172+
#[cfg_attr(
173+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes",
174+
doc = "See [`sql_dialect::on_conflict_clause`] for provided default implementations"
175+
)]
167176
type OnConflictClause;
168177
/// Configures how this backend handles the bare `DEFAULT` keyword for
169178
/// inserting the default value in a `INSERT INTO` `VALUES` clause
170179
///
171180
/// This allows backends to opt in support for `DEFAULT` value expressions
172181
/// for insert statements
173182
///
174-
/// See [`sql_dialect::default_keyword_for_insert`] for provided default implementations
183+
#[cfg_attr(
184+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes",
185+
doc = "See [`sql_dialect::default_keyword_for_insert`] for provided default implementations"
186+
)]
175187
type InsertWithDefaultKeyword;
176188
/// Configures how this backend handles Batch insert statements
177189
///
@@ -185,7 +197,10 @@ pub trait SqlDialect: self::private::TrustedBackend {
185197
doc = "implementation for `BatchInsert`"
186198
)]
187199
///
188-
/// See [`sql_dialect::batch_insert_support`] for provided default implementations
200+
#[cfg_attr(
201+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes",
202+
doc = "See [`sql_dialect::batch_insert_support`] for provided default implementations"
203+
)]
189204
type BatchInsertSupport;
190205
/// Configures how this backend handles the `DEFAULT VALUES` clause for
191206
/// insert statements.
@@ -200,7 +215,10 @@ pub trait SqlDialect: self::private::TrustedBackend {
200215
doc = "implementation for `DefaultValues`"
201216
)]
202217
///
203-
/// See [`sql_dialect::default_value_clause`] for provided default implementations
218+
#[cfg_attr(
219+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes",
220+
doc = "See [`sql_dialect::default_value_clause`] for provided default implementations"
221+
)]
204222
type DefaultValueClauseForInsert;
205223
/// Configures how this backend handles empty `FROM` clauses for select statements.
206224
///
@@ -214,7 +232,10 @@ pub trait SqlDialect: self::private::TrustedBackend {
214232
doc = "implementation for `NoFromClause`"
215233
)]
216234
///
217-
/// See [`sql_dialect::from_clause_syntax`] for provided default implementations
235+
#[cfg_attr(
236+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes",
237+
doc = "See [`sql_dialect::from_clause_syntax`] for provided default implementations"
238+
)]
218239
type EmptyFromClauseSyntax;
219240
/// Configures how this backend handles `EXISTS()` expressions.
220241
///
@@ -228,7 +249,10 @@ pub trait SqlDialect: self::private::TrustedBackend {
228249
doc = "implementation for `Exists`"
229250
)]
230251
///
231-
/// See [`sql_dialect::exists_syntax`] for provided default implementations
252+
#[cfg_attr(
253+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes",
254+
doc = "See [`sql_dialect::exists_syntax`] for provided default implementations"
255+
)]
232256
type ExistsSyntax;
233257

234258
/// Configures how this backend handles `IN()` and `NOT IN()` expressions.
@@ -245,18 +269,43 @@ pub trait SqlDialect: self::private::TrustedBackend {
245269
doc = "implementations for `In`, `NotIn` and `Many`"
246270
)]
247271
///
248-
/// See `[sql_dialect::array_comparison`] for provided default implementations
249-
type ArrayComparision;
272+
#[cfg_attr(
273+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes",
274+
doc = "See [`sql_dialect::array_comparison`] for provided default implementations"
275+
)]
276+
type ArrayComparison;
250277
}
251278

252279
/// This module contains all options provided by diesel to configure the [`SqlDialect`] trait.
253-
pub mod sql_dialect {
280+
// This module is only public behind the unstable feature flag, as we may want to change SqlDialect
281+
// implementations of existing backends because of:
282+
// * The backend gained support for previously unsupported SQL operations
283+
// * The backend fixed/introduced a bug that requires special handling
284+
// * We got some edge case wrong with sharing the implementation between backends
285+
//
286+
// By not exposing these types publically we are able to change the exact definitions later on
287+
// as users cannot write trait bounds that ensure that a specific type is used in place of
288+
// an existing associated type.
289+
#[diesel_derives::__diesel_public_if(
290+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
291+
)]
292+
pub(crate) mod sql_dialect {
293+
#![cfg_attr(
294+
not(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"),
295+
// Otherwise there are false positives
296+
// because the lint seems to believe that these pub statements
297+
// are not required, but they are required through the various backend impls
298+
allow(unreachable_pub)
299+
)]
254300
#[cfg(doc)]
255301
use super::SqlDialect;
256302

257303
/// This module contains all diesel provided reusable options to
258304
/// configure [`SqlDialect::OnConflictClause`]
259-
pub mod on_conflict_clause {
305+
#[diesel_derives::__diesel_public_if(
306+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
307+
)]
308+
pub(crate) mod on_conflict_clause {
260309
/// A marker trait indicating if a `ON CONFLICT` clause is supported or not
261310
///
262311
/// If you use a custom type to specify specialized support for `ON CONFLICT` clauses
@@ -271,7 +320,10 @@ pub mod sql_dialect {
271320

272321
/// This module contains all reusable options to configure
273322
/// [`SqlDialect::ReturningClause`]
274-
pub mod returning_clause {
323+
#[diesel_derives::__diesel_public_if(
324+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
325+
)]
326+
pub(crate) mod returning_clause {
275327
/// A marker trait indicating if a `RETURNING` clause is supported or not
276328
///
277329
/// If you use custom type to specify specialized support for `RETURNING` clauses
@@ -292,7 +344,10 @@ pub mod sql_dialect {
292344

293345
/// This module contains all reusable options to configure
294346
/// [`SqlDialect::InsertWithDefaultKeyword`]
295-
pub mod default_keyword_for_insert {
347+
#[diesel_derives::__diesel_public_if(
348+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
349+
)]
350+
pub(crate) mod default_keyword_for_insert {
296351
/// A marker trait indicating if a `DEFAULT` like expression
297352
/// is supported as part of `INSERT INTO` clauses to indicate
298353
/// that a default value should be inserted at a specific position
@@ -318,7 +373,10 @@ pub mod sql_dialect {
318373

319374
/// This module contains all reusable options to configure
320375
/// [`SqlDialect::BatchInsertSupport`]
321-
pub mod batch_insert_support {
376+
#[diesel_derives::__diesel_public_if(
377+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
378+
)]
379+
pub(crate) mod batch_insert_support {
322380
/// A marker trait indicating if batch insert statements
323381
/// are supported for this backend or not
324382
pub trait SupportsBatchInsert {}
@@ -341,7 +399,10 @@ pub mod sql_dialect {
341399

342400
/// This module contains all reusable options to configure
343401
/// [`SqlDialect::DefaultValueClauseForInsert`]
344-
pub mod default_value_clause {
402+
#[diesel_derives::__diesel_public_if(
403+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
404+
)]
405+
pub(crate) mod default_value_clause {
345406

346407
/// Indicates that this backend uses the
347408
/// `DEFAULT VALUES` syntax to specify
@@ -353,7 +414,10 @@ pub mod sql_dialect {
353414

354415
/// This module contains all reusable options to configure
355416
/// [`SqlDialect::EmptyFromClauseSyntax`]
356-
pub mod from_clause_syntax {
417+
#[diesel_derives::__diesel_public_if(
418+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
419+
)]
420+
pub(crate) mod from_clause_syntax {
357421

358422
/// Indicates that this backend skips
359423
/// the `FROM` clause in `SELECT` statements
@@ -364,7 +428,10 @@ pub mod sql_dialect {
364428

365429
/// This module contains all reusable options to configure
366430
/// [`SqlDialect::ExistsSyntax`]
367-
pub mod exists_syntax {
431+
#[diesel_derives::__diesel_public_if(
432+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
433+
)]
434+
pub(crate) mod exists_syntax {
368435

369436
/// Indicates that this backend
370437
/// treats `EXIST()` as function
@@ -374,8 +441,11 @@ pub mod sql_dialect {
374441
}
375442

376443
/// This module contains all reusable options to configure
377-
/// [`SqlDialect::ArrayComparision`]
378-
pub mod array_comparision {
444+
/// [`SqlDialect::ArrayComparison`]
445+
#[diesel_derives::__diesel_public_if(
446+
feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes"
447+
)]
448+
pub(crate) mod array_comparison {
379449

380450
/// Indicates that this backend requires a single bind
381451
/// per array element in `IN()` and `NOT IN()` expression

diesel/src/expression/array_comparison.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::marker::PhantomData;
2323
///
2424
/// Third party backend can customize the [`QueryFragment`]
2525
/// implementation of this query dsl node via
26-
/// [`SqlDialect::ArrayComparision`]. A customized implementation
26+
/// [`SqlDialect::ArrayComparison`]. A customized implementation
2727
/// is expected to provide the same sematics as a ANSI SQL
2828
/// `IN` expression.
2929
///
@@ -43,7 +43,7 @@ pub struct In<T, U> {
4343
///
4444
/// Third party backend can customize the [`QueryFragment`]
4545
/// implementation of this query dsl node via
46-
/// [`SqlDialect::ArrayComparision`]. A customized implementation
46+
/// [`SqlDialect::ArrayComparison`]. A customized implementation
4747
/// is expected to provide the same sematics as a ANSI SQL
4848
/// `NOT IN` expression.0
4949
///
@@ -89,18 +89,17 @@ where
8989
impl<T, U, DB> QueryFragment<DB> for In<T, U>
9090
where
9191
DB: Backend,
92-
Self: QueryFragment<DB, DB::ArrayComparision>,
92+
Self: QueryFragment<DB, DB::ArrayComparison>,
9393
{
9494
fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
95-
<Self as QueryFragment<DB, DB::ArrayComparision>>::walk_ast(self, pass)
95+
<Self as QueryFragment<DB, DB::ArrayComparison>>::walk_ast(self, pass)
9696
}
9797
}
9898

99-
impl<T, U, DB> QueryFragment<DB, sql_dialect::array_comparision::AnsiSqlArrayComparison>
100-
for In<T, U>
99+
impl<T, U, DB> QueryFragment<DB, sql_dialect::array_comparison::AnsiSqlArrayComparison> for In<T, U>
101100
where
102101
DB: Backend
103-
+ SqlDialect<ArrayComparision = sql_dialect::array_comparision::AnsiSqlArrayComparison>,
102+
+ SqlDialect<ArrayComparison = sql_dialect::array_comparison::AnsiSqlArrayComparison>,
104103
T: QueryFragment<DB>,
105104
U: QueryFragment<DB> + MaybeEmpty,
106105
{
@@ -120,18 +119,18 @@ where
120119
impl<T, U, DB> QueryFragment<DB> for NotIn<T, U>
121120
where
122121
DB: Backend,
123-
Self: QueryFragment<DB, DB::ArrayComparision>,
122+
Self: QueryFragment<DB, DB::ArrayComparison>,
124123
{
125124
fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
126-
<Self as QueryFragment<DB, DB::ArrayComparision>>::walk_ast(self, pass)
125+
<Self as QueryFragment<DB, DB::ArrayComparison>>::walk_ast(self, pass)
127126
}
128127
}
129128

130-
impl<T, U, DB> QueryFragment<DB, sql_dialect::array_comparision::AnsiSqlArrayComparison>
129+
impl<T, U, DB> QueryFragment<DB, sql_dialect::array_comparison::AnsiSqlArrayComparison>
131130
for NotIn<T, U>
132131
where
133132
DB: Backend
134-
+ SqlDialect<ArrayComparision = sql_dialect::array_comparision::AnsiSqlArrayComparison>,
133+
+ SqlDialect<ArrayComparison = sql_dialect::array_comparison::AnsiSqlArrayComparison>,
135134
T: QueryFragment<DB>,
136135
U: QueryFragment<DB> + MaybeEmpty,
137136
{
@@ -234,7 +233,7 @@ where
234233
///
235234
/// Third party backend can customize the [`QueryFragment`]
236235
/// implementation of this query dsl node via
237-
/// [`SqlDialect::ArrayComparision`]. The default
236+
/// [`SqlDialect::ArrayComparison`]. The default
238237
/// implementation does generate one bind per value
239238
/// in the `values` field.
240239
///
@@ -290,20 +289,20 @@ where
290289

291290
impl<ST, I, DB> QueryFragment<DB> for Many<ST, I>
292291
where
293-
Self: QueryFragment<DB, DB::ArrayComparision>,
292+
Self: QueryFragment<DB, DB::ArrayComparison>,
294293
DB: Backend,
295294
{
296295
fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
297-
<Self as QueryFragment<DB, DB::ArrayComparision>>::walk_ast(self, pass)
296+
<Self as QueryFragment<DB, DB::ArrayComparison>>::walk_ast(self, pass)
298297
}
299298
}
300299

301-
impl<ST, I, DB> QueryFragment<DB, sql_dialect::array_comparision::AnsiSqlArrayComparison>
300+
impl<ST, I, DB> QueryFragment<DB, sql_dialect::array_comparison::AnsiSqlArrayComparison>
302301
for Many<ST, I>
303302
where
304303
DB: Backend
305304
+ HasSqlType<ST>
306-
+ SqlDialect<ArrayComparision = sql_dialect::array_comparision::AnsiSqlArrayComparison>,
305+
+ SqlDialect<ArrayComparison = sql_dialect::array_comparison::AnsiSqlArrayComparison>,
307306
ST: SingleValue,
308307
I: ToSql<ST, DB>,
309308
{

diesel/src/mysql/backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl SqlDialect for Mysql {
8989
type EmptyFromClauseSyntax = sql_dialect::from_clause_syntax::AnsiSqlFromClauseSyntax;
9090
type ExistsSyntax = sql_dialect::exists_syntax::AnsiSqlExistsSyntax;
9191

92-
type ArrayComparision = sql_dialect::array_comparision::AnsiSqlArrayComparison;
92+
type ArrayComparison = sql_dialect::array_comparison::AnsiSqlArrayComparison;
9393
}
9494

9595
impl DieselReserveSpecialization for Mysql {}

diesel/src/pg/backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl SqlDialect for Pg {
140140

141141
type EmptyFromClauseSyntax = sql_dialect::from_clause_syntax::AnsiSqlFromClauseSyntax;
142142
type ExistsSyntax = sql_dialect::exists_syntax::AnsiSqlExistsSyntax;
143-
type ArrayComparision = PgStyleArrayComparision;
143+
type ArrayComparison = PgStyleArrayComparision;
144144
}
145145

146146
impl DieselReserveSpecialization for Pg {}

diesel/src/sqlite/backend.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl SqlDialect for Sqlite {
5959
#[cfg(feature = "returning_clauses_for_sqlite_3_35")]
6060
type ReturningClause = sql_dialect::returning_clause::PgLikeReturningClause;
6161

62-
type OnConflictClause = SqliteOnConflictClaues;
62+
type OnConflictClause = SqliteOnConflictClause;
6363

6464
type InsertWithDefaultKeyword =
6565
sql_dialect::default_keyword_for_insert::DoesNotSupportDefaultKeyword;
@@ -68,16 +68,16 @@ impl SqlDialect for Sqlite {
6868

6969
type EmptyFromClauseSyntax = sql_dialect::from_clause_syntax::AnsiSqlFromClauseSyntax;
7070
type ExistsSyntax = sql_dialect::exists_syntax::AnsiSqlExistsSyntax;
71-
type ArrayComparision = sql_dialect::array_comparision::AnsiSqlArrayComparison;
71+
type ArrayComparison = sql_dialect::array_comparison::AnsiSqlArrayComparison;
7272
}
7373

7474
impl DieselReserveSpecialization for Sqlite {}
7575
impl TrustedBackend for Sqlite {}
7676

7777
#[derive(Debug, Copy, Clone)]
78-
pub struct SqliteOnConflictClaues;
78+
pub struct SqliteOnConflictClause;
7979

80-
impl sql_dialect::on_conflict_clause::SupportsOnConflictClause for SqliteOnConflictClaues {}
80+
impl sql_dialect::on_conflict_clause::SupportsOnConflictClause for SqliteOnConflictClause {}
8181

8282
#[derive(Debug, Copy, Clone)]
8383
pub struct SqliteBatchInsert;

0 commit comments

Comments
 (0)