Skip to content

Commit

Permalink
Merge pull request #4193 from guissalustiano/multirange_functions
Browse files Browse the repository at this point in the history
Extend range functions to support nullable and multirange
  • Loading branch information
weiznich authored Aug 23, 2024
2 parents 2e049a4 + 36a76a2 commit faaf4e8
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 159 deletions.
37 changes: 32 additions & 5 deletions diesel/src/pg/expression/expression_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pub(in crate::pg) use self::private::{
ArrayOrNullableArray, InetOrCidr, JsonIndex, JsonOrNullableJsonOrJsonbOrNullableJsonb,
JsonRemoveIndex, JsonbOrNullableJsonb, MultirangeOrRangeMaybeNullable, RangeHelper,
RangeOrNullableRange, TextOrNullableText,
JsonRemoveIndex, JsonbOrNullableJsonb, MultirangeOrNullableMultirange,
MultirangeOrRangeMaybeNullable, RangeHelper, RangeOrNullableRange, TextOrNullableText,
};
use super::date_and_time::{AtTimeZone, DateTimeLike};
use super::operators::*;
Expand Down Expand Up @@ -3485,10 +3485,37 @@ pub(in crate::pg) mod private {
message = "`{Self}` is neither `diesel::sql_types::Range<_>` nor `diesel::sql_types::Nullable<Range<_>>`",
note = "try to provide an expression that produces one of the expected sql types"
)]
pub trait RangeOrNullableRange {}
pub trait RangeOrNullableRange {
type Inner: SingleValue;
}

impl<ST> RangeOrNullableRange for Range<ST> {}
impl<ST> RangeOrNullableRange for Nullable<Range<ST>> {}
impl<ST: SingleValue> RangeOrNullableRange for Range<ST> {
type Inner = ST;
}
impl<ST: SingleValue> RangeOrNullableRange for Nullable<Range<ST>> {
type Inner = ST;
}

/// Marker trait used to implement `PgRangeExpressionMethods` on the appropriate
/// types. Once coherence takes associated types into account, we can remove
/// this trait.
#[diagnostic::on_unimplemented(
message = "`{Self}` is neither `diesel::sql_types::Range<_>` nor `diesel::sql_types::Nullable<Range<_>>`",
note = "try to provide an expression that produces one of the expected sql types"
)]
pub trait MultirangeOrNullableMultirange {
type Inner: SingleValue;
type Range: SingleValue;
}

impl<ST: SingleValue> MultirangeOrNullableMultirange for Multirange<ST> {
type Inner = ST;
type Range = Range<ST>;
}
impl<ST: SingleValue> MultirangeOrNullableMultirange for Nullable<Multirange<ST>> {
type Inner = ST;
type Range = Nullable<Range<ST>>;
}

/// Marker trait used to implement `PgRangeExpressionMethods` on the appropriate
/// types. Once coherence takes associated types into account, we can remove
Expand Down
Loading

0 comments on commit faaf4e8

Please sign in to comment.