Skip to content

Commit

Permalink
Merge pull request #4180 from liamw1/master
Browse files Browse the repository at this point in the history
Added support for missing operations on Citext
  • Loading branch information
weiznich authored Aug 18, 2024
2 parents cee97fb + 46035a5 commit f17e60c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions diesel/src/expression/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,9 @@ pub trait LikeIsAllowedForType<ST>: Backend {}

impl<DB> LikeIsAllowedForType<crate::sql_types::Text> for DB where DB: Backend {}

#[cfg(feature = "postgres_backend")]
impl LikeIsAllowedForType<crate::pg::sql_types::Citext> for crate::pg::Pg {}

impl<T, DB> LikeIsAllowedForType<crate::sql_types::Nullable<T>> for DB where
DB: Backend + LikeIsAllowedForType<T>
{
Expand Down
5 changes: 5 additions & 0 deletions diesel/src/expression_methods/text_expression_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,9 @@ mod private {

impl TextOrNullableText for Text {}
impl TextOrNullableText for Nullable<Text> {}

#[cfg(feature = "postgres_backend")]
impl TextOrNullableText for crate::pg::sql_types::Citext {}
#[cfg(feature = "postgres_backend")]
impl TextOrNullableText for Nullable<crate::pg::sql_types::Citext> {}
}
2 changes: 2 additions & 0 deletions diesel/src/sql_types/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ impl<T> SqlOrd for sql_types::Nullable<T> where T: SqlOrd + SqlType<IsNull = is_
#[cfg(feature = "postgres_backend")]
impl SqlOrd for sql_types::Timestamptz {}
#[cfg(feature = "postgres_backend")]
impl SqlOrd for sql_types::Citext {}
#[cfg(feature = "postgres_backend")]
impl<T: SqlOrd> SqlOrd for sql_types::Array<T> {}

#[cfg(feature = "mysql_backend")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ error[E0277]: expressions of the type `diesel::sql_types::Bool` cannot be ordere
= help: the following other types implement trait `SqlOrd`:
Array<T>
BigInt
Citext
Datetime
Interval
Nullable<T>
Unsigned<BigInt>
Unsigned<diesel::sql_types::Integer>
Unsigned<diesel::sql_types::SmallInt>
and $N others
= note: required for `diesel::sql_types::Bool` to implement `diesel::expression::functions::aggregate_ordering::private::SqlOrdAggregate`
= note: required for `diesel::expression::functions::aggregate_ordering::max_utils::max<diesel::sql_types::Bool, columns::b>` to implement `diesel::Expression`
Expand Down Expand Up @@ -53,12 +53,12 @@ error[E0277]: expressions of the type `diesel::sql_types::Bool` cannot be ordere
= help: the following other types implement trait `SqlOrd`:
Array<T>
BigInt
Citext
Datetime
Interval
Nullable<T>
Unsigned<BigInt>
Unsigned<diesel::sql_types::Integer>
Unsigned<diesel::sql_types::SmallInt>
and $N others
= note: required for `diesel::sql_types::Bool` to implement `diesel::expression::functions::aggregate_ordering::private::SqlOrdAggregate`
= note: required for `diesel::expression::functions::aggregate_ordering::min_utils::min<diesel::sql_types::Bool, columns::b>` to implement `diesel::Expression`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ error[E0277]: Cannot use the `LIKE` operator with expressions of the type `diese
allowed for all backends
= note: Expressions of the type `diesel::sql_types::Binary` and `diesel::sql_types::Nullable<Binary>` are
allowed for the PostgreSQL backend
= help: the trait `diesel::expression::operators::LikeIsAllowedForType<diesel::sql_types::Binary>` is implemented for `Pg`
= help: the following other types implement trait `diesel::expression::operators::LikeIsAllowedForType<ST>`:
<Pg as diesel::expression::operators::LikeIsAllowedForType<Citext>>
<Pg as diesel::expression::operators::LikeIsAllowedForType<diesel::sql_types::Binary>>
= note: required for `diesel::expression::operators::Like<columns::name, diesel::expression::bound::Bound<diesel::sql_types::Binary, Vec<u8>>>` to implement `QueryFragment<Sqlite>`
= note: 6 redundant requirements hidden
= note: required for `SelectStatement<FromClause<table>, SelectClause<Grouped<Concat<name, Bound<Binary, Vec<u8>>>>>, ..., ...>` to implement `QueryFragment<Sqlite>`
Expand Down Expand Up @@ -38,7 +40,9 @@ error[E0277]: Cannot use the `LIKE` operator with expressions of the type `diese
allowed for all backends
= note: Expressions of the type `diesel::sql_types::Binary` and `diesel::sql_types::Nullable<Binary>` are
allowed for the PostgreSQL backend
= help: the trait `diesel::expression::operators::LikeIsAllowedForType<diesel::sql_types::Binary>` is implemented for `Pg`
= help: the following other types implement trait `diesel::expression::operators::LikeIsAllowedForType<ST>`:
<Pg as diesel::expression::operators::LikeIsAllowedForType<Citext>>
<Pg as diesel::expression::operators::LikeIsAllowedForType<diesel::sql_types::Binary>>
= note: required for `diesel::expression::operators::Like<columns::name, diesel::expression::bound::Bound<diesel::sql_types::Binary, Vec<u8>>>` to implement `QueryFragment<Mysql>`
= note: 6 redundant requirements hidden
= note: required for `SelectStatement<FromClause<table>, SelectClause<Grouped<Concat<name, Bound<Binary, Vec<u8>>>>>, ..., ...>` to implement `QueryFragment<Mysql>`
Expand Down

0 comments on commit f17e60c

Please sign in to comment.