Skip to content
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

Add EntityClass#test(id) and support update { it[nullable] = nullable } #1277

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

vlsi
Copy link

@vlsi vlsi commented Jun 19, 2021

Sorry for 7 commits in a single PR, however, I expect they could just land to the main branch as is, and creating 7 different PR and rebasing them 6 times (after each gets merged) would be unnecessary overhead (for both of you and me).

Notes:

  1. I adjusted generics in UpdateBuilder, so there's one type parameter and others are moved to function arguments. That makes exceptions slightly easier to read and understand.

  2. I would like to reorder set functions in UpdateBuilder: first put 2 setters for regular column type, then 2 setters for EntityID column. However, I did not do that because it would make review/comparison harder. I can do that in a separate commit if you like.

  3. it[nullableRef] = null does not compile now. I have no idea how to solve it as it can't decide between null as Int? and null as EntityID<Int>?. The workaround is to use null as EntityID<Int>?. It might make sense to add UpdateBuilder#setNull(Column) API so users could write:

    fun <T> setNull(column: Column<T?>) = set(column, null as T?)
    
    update {
        it.setNull(y1) // instead of it[y1] = null
    }
    

Fixes #1275, #1276, #1268

operator fun <S : Comparable<S>, ID : EntityID<S>, E : S?> set(column: Column<ID>, value: E) {
operator fun <S : Comparable<S>> set(column: Column<out EntityID<S>?>, value: S?) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the key signature change to support it[nullableIntRef] = null as Int?. The rest (e.g. out) is done to keep existing tests pass, and make code consistent.

@vlsi vlsi force-pushed the issues_1275_1276 branch 7 times, most recently from 6dcfb99 to f63b330 Compare June 19, 2021 20:36
vlsi added 2 commits June 20, 2021 00:29
Key change is UpdateBuilder#setWithEntityIdValue, which now accepts
column: Column<out EntityID<S>?>, value: S?
previous signature was
column: Column<out EntityID<S>>, value: S?

A downside is that "[optionalReferenceColumn] = null" can't decide between
"null as ColumnType?" and "null as EntityID<ColumnType>?"

update {
  // it[optionalReferenceColumn] = null // <- does not work
  // Workaround: specify null type explicitly to call the proper overload
  it[optionalReferenceColumn] = null as EntityID<ColumnType>?
  // The following works as well:
  // it[optionalReferenceColumn] = null as ColumnType?
}

fixes JetBrains#1275
@vlsi vlsi force-pushed the issues_1275_1276 branch 3 times, most recently from 1fb6ca7 to be4042e Compare June 19, 2021 21:35
* Exception message would include the relevant table and column name
* LiteralOp(...) and QueryParameter(...) would fail if user creates NULL value for non-nullable type
* Single-value QueryBuilder#registerArgument is slightly faster as it no longer creates list

fixes JetBrains#1268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optReference column should allow update { it[column] = nullableValue }
1 participant