-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: EXPOSED-577 Allow Entity and EntityID parameters to not be Comparable #2277
Conversation
class Max<T : Comparable<T>, in S : T?>( | ||
class Max<T : Any, in S : T?>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes were only made because our tests had use cases like TestTable.id.max()
.
@e5l @obabichevjb This now leads to the question, what about other restricted functions, like Avg()
, which only accepts Comparable column types?
Should it still be possible to call avg()
on an entityID column like TestTable.id.avg()
or does that use case make no sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s a good question. At first glance, it seems like it shouldn't be Comparable
, especially for Max
functions, if it’s only comparable on the database side. I can’t think of a specific example right now, but imagine something that can have Max
applied to it in the database but doesn’t have a comparable representation in Kotlin.
Since we get from SQL just single value and don't compare it on client side, it could be non-comparable.
get() = _idColumns.ifEmpty { | ||
val message = "Table definition must include id columns. Please use Column.entityId() or IdTable.addIdColumn()." | ||
exposedLogger.error(message) | ||
error(message) | ||
} | ||
|
||
/** Adds a column to [idColumns] so that it can be used as a component of the [id] property. */ | ||
protected fun <S : Comparable<S>> addIdColumn(newColumn: Column<EntityID<S>>) { | ||
protected fun <S : Any> addIdColumn(newColumn: Column<EntityID<S>>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, is Any
here to indicate that S
not nullable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was the assumption I made about most cases. Do you think it's not an ok assumption that may lead to breaking changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was non-nullable Comparable
, so I expect that it should be fine to replace it with non-nullable Any
. To make it weaker in the future should be easier then vice versa anyway.
class Max<T : Comparable<T>, in S : T?>( | ||
class Max<T : Any, in S : T?>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s a good question. At first glance, it seems like it shouldn't be Comparable
, especially for Max
functions, if it’s only comparable on the database side. I can’t think of a specific example right now, but imagine something that can have Max
applied to it in the database but doesn’t have a comparable representation in Kotlin.
Since we get from SQL just single value and don't compare it on client side, it could be non-comparable.
- EntityID still implements Comparable interface itself
…parable - Add breaking changes notes - EntityID and CompositeID no longer implement Comparable - Min and Max are no longer restricted to Comparable - References are also no longer restricted
…parable - Add note in breaking change about use of entity id with functions restricted to Comparable
3eb80f2
to
5fd1a42
Compare
Description
Summary of the change:
All
Entity
related objects and functions are no longer restricted to type-parameterComparable
.Detailed description:
Why:
Introduction of Kotlin 2.0 brought
kotlin.uuid.Uuid
, which does not implementComparable
interface, and many requests to allow its usage withIdTable
. Loosening these type restrictions will allow users to easily implement their ownUuidColumnType
andIdTable<Uuid>
, at least until the new type is no longer@ExperimentalUuidApi
and built-in Exposed api options are made available.How:
T : Comparable<T>
has been replaced withT : Any
.Min
andMax
class operators are also no longer restricted toComparable
types, so thatmax()
andmin()
can be called onid
. This was done because some tests presented this use case.Comparable
to allow use of these functions withid
columns.EntityID
andCompositeID
are no longerComparable
, since their wrapped values are no longer restricted to this. This means that any use of these directly with comparison operators, or any variant of sort orcompareTo()
, will no longer compile:Type of Change
Please mark the relevant options with an "X":
Updates/remove existing public API methods:
Affected databases:
Checklist
Related Issues
EXPOSED-577