Skip to content

Commit

Permalink
Merge pull request #4343 from weiznich/prepare/2.2.5
Browse files Browse the repository at this point in the history
Prepare a diesel 2.2.5 release
  • Loading branch information
weiznich authored Nov 21, 2024
2 parents 291e66d + f89990e commit 5365506
Show file tree
Hide file tree
Showing 83 changed files with 1,532 additions and 1,679 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@ Increasing the minimal supported Rust version will always be coupled at least wi

## Unreleased

## [2.2.4] 2024-09-3
## [2.2.5] 2024-11-21

### Fixed

* Add a typedef for `Returning` and `Count` so that `#[auto_type]` works with such queries
* Fixed an issue that allowed to pass non-boolean expressions to `.and()` and `.or()` which would
result in queries failing at runtime
* Officially deprecating the gitter room

### Removed

* Do not mention the gitter channel in our docs anymore

## [2.2.4] 2024-09-03

### Fixed

Expand Down Expand Up @@ -2144,3 +2157,4 @@ queries or set `PIPES_AS_CONCAT` manually.
[2.2.2]: https://github.com/diesel-rs/diesel/compare/v.2.2.1...v2.2.2
[2.2.3]: https://github.com/diesel-rs/diesel/compare/v.2.2.2...v2.2.3
[2.2.4]: https://github.com/diesel-rs/diesel/compare/v.2.2.3...v2.2.4
[2.2.5]: https://github.com/diesel-rs/diesel/compare/v.2.2.4...v2.2.5
2 changes: 1 addition & 1 deletion diesel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diesel"
version = "2.2.4"
version = "2.2.5"
license = "MIT OR Apache-2.0"
description = "A safe, extensible ORM and Query Builder for PostgreSQL, SQLite, and MySQL"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions diesel/src/expression_methods/bool_expression_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub trait BoolExpressionMethods: Expression + Sized {
fn and<T, ST>(self, other: T) -> dsl::And<Self, T, ST>
where
Self::SqlType: SqlType,
ST: SqlType + TypedExpressionType,
ST: SqlType + TypedExpressionType + BoolOrNullableBool,
T: AsExpression<ST>,
And<Self, T::Expression>: Expression,
{
Expand Down Expand Up @@ -89,7 +89,7 @@ pub trait BoolExpressionMethods: Expression + Sized {
fn or<T, ST>(self, other: T) -> dsl::Or<Self, T, ST>
where
Self::SqlType: SqlType,
ST: SqlType + TypedExpressionType,
ST: SqlType + TypedExpressionType + BoolOrNullableBool,
T: AsExpression<ST>,
Or<Self, T::Expression>: Expression,
{
Expand Down
16 changes: 13 additions & 3 deletions diesel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@
//! ## Getting help
//!
//! If you run into problems, Diesel has an active community.
//! Either open a new [discussion] thread at diesel github repository or
//! use the active Gitter room at
//! [gitter.im/diesel-rs/diesel](https://gitter.im/diesel-rs/diesel)
//! Open a new [discussion] thread at diesel github repository
//! and we will try to help you
//!
//! [discussion]: https://github.com/diesel-rs/diesel/discussions/categories/q-a
//!
Expand Down Expand Up @@ -358,6 +357,7 @@ pub mod helper_types {
use super::query_dsl::methods::*;
use super::query_dsl::*;
use super::query_source::{aliasing, joins};
use crate::dsl::CountStar;
use crate::query_builder::select_clause::SelectClause;

#[doc(inline)]
Expand Down Expand Up @@ -676,6 +676,16 @@ pub mod helper_types {
<U as crate::query_builder::update_statement::UpdateAutoTypeHelper>::Where,
<V as crate::AsChangeset>::Changeset,
>;

/// Represents the return type of
/// [`InsertStatement::returning`](crate::query_builder::InsertStatement::returning),
/// [`UpdateStatement::returning`] and
/// [`DeleteStatement::returning`](crate::query_builder::DeleteStatement::returning)
pub type Returning<Q, S> =
<Q as crate::query_builder::returning_clause::ReturningClauseHelper<S>>::WithReturning;

#[doc(hidden)] // used for `QueryDsl::count`
pub type Count<Q> = Select<Q, CountStar>;
}

pub mod prelude {
Expand Down
29 changes: 29 additions & 0 deletions diesel/src/query_builder/returning_clause.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use super::DeleteStatement;
use super::InsertStatement;
use super::UpdateStatement;
use super::{AstPass, QueryFragment};
use crate::backend::{Backend, DieselReserveSpecialization};
use crate::query_builder::QueryId;
use crate::result::QueryResult;
use crate::QuerySource;

#[derive(Debug, Clone, Copy, QueryId)]
pub struct NoReturningClause;
Expand Down Expand Up @@ -52,3 +56,28 @@ where
Ok(())
}
}

pub trait ReturningClauseHelper<S> {
type WithReturning;
}

impl<S, T, U, Op> ReturningClauseHelper<S> for InsertStatement<T, U, Op>
where
T: QuerySource,
{
type WithReturning = InsertStatement<T, U, Op, ReturningClause<S>>;
}

impl<S, T, U, V> ReturningClauseHelper<S> for UpdateStatement<T, U, V>
where
T: QuerySource,
{
type WithReturning = UpdateStatement<T, U, V, ReturningClause<S>>;
}

impl<S, T, U> ReturningClauseHelper<S> for DeleteStatement<T, U>
where
T: QuerySource,
{
type WithReturning = DeleteStatement<T, U, ReturningClause<S>>;
}
1 change: 1 addition & 0 deletions diesel/src/test_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(missing_docs)]
extern crate dotenvy;

use crate::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion diesel_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "diesel_cli"
version = "2.2.4"
version = "2.2.5"
license = "MIT OR Apache-2.0"
description = "Provides the CLI for the Diesel crate"
readme = "README.md"
Expand Down
18 changes: 12 additions & 6 deletions diesel_compile_tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ error[E0277]: Cannot select `posts::columns::id` from `users::table`
|
= note: `posts::columns::id` is no valid selection for `users::table`
= help: the following other types implement trait `SelectableExpression<QS>`:
<posts::columns::id as SelectableExpression<JoinOn<Join, On>>>
<posts::columns::id as SelectableExpression<Only<posts::table>>>
<posts::columns::id as SelectableExpression<SelectStatement<FromClause<From>>>>
<posts::columns::id as SelectableExpression<Tablesample<posts::table, TSM>>>
<posts::columns::id as SelectableExpression<posts::table>>
<posts::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, Inner>>>
<posts::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, LeftOuter>>>
`posts::columns::id` implements `SelectableExpression<JoinOn<Join, On>>`
`posts::columns::id` implements `SelectableExpression<Only<posts::table>>`
`posts::columns::id` implements `SelectableExpression<SelectStatement<FromClause<From>>>`
`posts::columns::id` implements `SelectableExpression<Tablesample<posts::table, TSM>>`
`posts::columns::id` implements `SelectableExpression<posts::table>`
`posts::columns::id` implements `SelectableExpression<query_source::joins::Join<Left, Right, Inner>>`
`posts::columns::id` implements `SelectableExpression<query_source::joins::Join<Left, Right, LeftOuter>>`
= note: required for `diesel::expression::functions::aggregate_folding::sum_utils::sum<diesel::sql_types::Integer, posts::columns::id>` to implement `SelectableExpression<users::table>`
= note: required for `SelectStatement<FromClause<users::table>>` to implement `SelectDsl<diesel::expression::functions::aggregate_folding::sum_utils::sum<diesel::sql_types::Integer, posts::columns::id>>`

Expand Down Expand Up @@ -41,13 +41,13 @@ error[E0277]: Cannot select `posts::columns::id` from `users::table`
|
= note: `posts::columns::id` is no valid selection for `users::table`
= help: the following other types implement trait `SelectableExpression<QS>`:
<posts::columns::id as SelectableExpression<JoinOn<Join, On>>>
<posts::columns::id as SelectableExpression<Only<posts::table>>>
<posts::columns::id as SelectableExpression<SelectStatement<FromClause<From>>>>
<posts::columns::id as SelectableExpression<Tablesample<posts::table, TSM>>>
<posts::columns::id as SelectableExpression<posts::table>>
<posts::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, Inner>>>
<posts::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, LeftOuter>>>
`posts::columns::id` implements `SelectableExpression<JoinOn<Join, On>>`
`posts::columns::id` implements `SelectableExpression<Only<posts::table>>`
`posts::columns::id` implements `SelectableExpression<SelectStatement<FromClause<From>>>`
`posts::columns::id` implements `SelectableExpression<Tablesample<posts::table, TSM>>`
`posts::columns::id` implements `SelectableExpression<posts::table>`
`posts::columns::id` implements `SelectableExpression<query_source::joins::Join<Left, Right, Inner>>`
`posts::columns::id` implements `SelectableExpression<query_source::joins::Join<Left, Right, LeftOuter>>`
= note: required for `diesel::expression::functions::aggregate_folding::avg_utils::avg<diesel::sql_types::Integer, posts::columns::id>` to implement `SelectableExpression<users::table>`
= note: required for `SelectStatement<FromClause<users::table>>` to implement `SelectDsl<diesel::expression::functions::aggregate_folding::avg_utils::avg<diesel::sql_types::Integer, posts::columns::id>>`

Expand Down Expand Up @@ -76,13 +76,13 @@ error[E0277]: Cannot select `posts::columns::id` from `users::table`
|
= note: `posts::columns::id` is no valid selection for `users::table`
= help: the following other types implement trait `SelectableExpression<QS>`:
<posts::columns::id as SelectableExpression<JoinOn<Join, On>>>
<posts::columns::id as SelectableExpression<Only<posts::table>>>
<posts::columns::id as SelectableExpression<SelectStatement<FromClause<From>>>>
<posts::columns::id as SelectableExpression<Tablesample<posts::table, TSM>>>
<posts::columns::id as SelectableExpression<posts::table>>
<posts::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, Inner>>>
<posts::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, LeftOuter>>>
`posts::columns::id` implements `SelectableExpression<JoinOn<Join, On>>`
`posts::columns::id` implements `SelectableExpression<Only<posts::table>>`
`posts::columns::id` implements `SelectableExpression<SelectStatement<FromClause<From>>>`
`posts::columns::id` implements `SelectableExpression<Tablesample<posts::table, TSM>>`
`posts::columns::id` implements `SelectableExpression<posts::table>`
`posts::columns::id` implements `SelectableExpression<query_source::joins::Join<Left, Right, Inner>>`
`posts::columns::id` implements `SelectableExpression<query_source::joins::Join<Left, Right, LeftOuter>>`
= note: required for `diesel::expression::functions::aggregate_ordering::max_utils::max<diesel::sql_types::Integer, posts::columns::id>` to implement `SelectableExpression<users::table>`
= note: required for `SelectStatement<FromClause<users::table>>` to implement `SelectDsl<diesel::expression::functions::aggregate_ordering::max_utils::max<diesel::sql_types::Integer, posts::columns::id>>`

Expand Down Expand Up @@ -111,13 +111,13 @@ error[E0277]: Cannot select `posts::columns::id` from `users::table`
|
= note: `posts::columns::id` is no valid selection for `users::table`
= help: the following other types implement trait `SelectableExpression<QS>`:
<posts::columns::id as SelectableExpression<JoinOn<Join, On>>>
<posts::columns::id as SelectableExpression<Only<posts::table>>>
<posts::columns::id as SelectableExpression<SelectStatement<FromClause<From>>>>
<posts::columns::id as SelectableExpression<Tablesample<posts::table, TSM>>>
<posts::columns::id as SelectableExpression<posts::table>>
<posts::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, Inner>>>
<posts::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, LeftOuter>>>
`posts::columns::id` implements `SelectableExpression<JoinOn<Join, On>>`
`posts::columns::id` implements `SelectableExpression<Only<posts::table>>`
`posts::columns::id` implements `SelectableExpression<SelectStatement<FromClause<From>>>`
`posts::columns::id` implements `SelectableExpression<Tablesample<posts::table, TSM>>`
`posts::columns::id` implements `SelectableExpression<posts::table>`
`posts::columns::id` implements `SelectableExpression<query_source::joins::Join<Left, Right, Inner>>`
`posts::columns::id` implements `SelectableExpression<query_source::joins::Join<Left, Right, LeftOuter>>`
= note: required for `diesel::expression::functions::aggregate_ordering::min_utils::min<diesel::sql_types::Integer, posts::columns::id>` to implement `SelectableExpression<users::table>`
= note: required for `SelectStatement<FromClause<users::table>>` to implement `SelectDsl<diesel::expression::functions::aggregate_ordering::min_utils::min<diesel::sql_types::Integer, posts::columns::id>>`

Expand Down
3 changes: 1 addition & 2 deletions diesel_compile_tests/tests/fail/alias_and_group_by.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ note: required for `columns::id` to implement `ValidGrouping<columns::name>`
= note: associated types for the current `impl` cannot be restricted in `where` clauses
= note: 1 redundant requirement hidden
= note: required for `AliasedField<user1, columns::id>` to implement `ValidGrouping<AliasedField<user1, columns::name>>`
= note: required for `SelectStatement<FromClause<Alias<user1>>, DefaultSelectClause<FromClause<...>>, ..., ..., ..., ..., ...>` to implement `SelectDsl<AliasedField<user1, columns::id>>`
= note: consider using `--verbose` to print the full type name to the console
= note: required for `SelectStatement<FromClause<Alias<user1>>, diesel::query_builder::select_clause::DefaultSelectClause<FromClause<Alias<user1>>>, diesel::query_builder::distinct_clause::NoDistinctClause, diesel::query_builder::where_clause::NoWhereClause, diesel::query_builder::order_clause::NoOrderClause, LimitOffsetClause<NoLimitClause, NoOffsetClause>, diesel::query_builder::group_by_clause::GroupByClause<AliasedField<user1, columns::name>>>` to implement `SelectDsl<AliasedField<user1, columns::id>>`
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extern crate diesel;

use diesel::prelude::*;

table! {
users {
id -> Integer,
name -> VarChar,
}
}

fn main() {
let conn = &mut PgConnection::establish("…").unwrap();
users::table
.filter(users::id.eq(1).and(users::id).or(users::id))
.select(users::id)
.execute(conn)
.unwrap();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error[E0277]: `diesel::sql_types::Integer` is neither `diesel::sql_types::Bool` nor `diesel::sql_types::Nullable<Bool>`
--> tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.rs:15:33
|
15 | .filter(users::id.eq(1).and(users::id).or(users::id))
| ^^^ the trait `BoolOrNullableBool` is not implemented for `diesel::sql_types::Integer`
|
= note: try to provide an expression that produces one of the expected sql types
= help: the following other types implement trait `BoolOrNullableBool`:
Bool
Nullable<Bool>
note: required by a bound in `diesel::BoolExpressionMethods::and`
--> $DIESEL/src/expression_methods/bool_expression_methods.rs
|
| fn and<T, ST>(self, other: T) -> dsl::And<Self, T, ST>
| --- required by a bound in this associated function
...
| ST: SqlType + TypedExpressionType + BoolOrNullableBool,
| ^^^^^^^^^^^^^^^^^^ required by this bound in `BoolExpressionMethods::and`

error[E0277]: `diesel::sql_types::Integer` is neither `diesel::sql_types::Bool` nor `diesel::sql_types::Nullable<Bool>`
--> tests/fail/and_or_functions_must_take_boolean_expr_as_attributes.rs:15:48
|
15 | .filter(users::id.eq(1).and(users::id).or(users::id))
| ^^ the trait `BoolOrNullableBool` is not implemented for `diesel::sql_types::Integer`
|
= note: try to provide an expression that produces one of the expected sql types
= help: the following other types implement trait `BoolOrNullableBool`:
Bool
Nullable<Bool>
note: required by a bound in `diesel::BoolExpressionMethods::or`
--> $DIESEL/src/expression_methods/bool_expression_methods.rs
|
| fn or<T, ST>(self, other: T) -> dsl::Or<Self, T, ST>
| -- required by a bound in this associated function
...
| ST: SqlType + TypedExpressionType + BoolOrNullableBool,
| ^^^^^^^^^^^^^^^^^^ required by this bound in `BoolExpressionMethods::or`
Loading

0 comments on commit 5365506

Please sign in to comment.