Hey, something that has been bugging me for a few ...
# exposed
h
Hey, something that has been bugging me for a few weeks, but I am unsure if it's a me, IntelliJ or exposed problem. Whenever I use
.deleteWhere
with
eq
it says that it can't resolve
eq
, and also does not offer any imports. I have to manually add
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
to the imports. Example:
Copy code
override fun deleteEntries(productionStateId: ProductionStateId) = database.transaction {
    ProductionStateEntryTable
        .deleteWhere { ProductionStateEntryTable.productionStateId eq productionStateId.value }
}
Curiously, once I add the above import it points to the exact same spot when I follow the reference to
SQLExpressionBuilder.kt
in
org.jetbrains.exposed.sql.ISqlExpressionBuilder
Even the inspect for a "where eq" and a "deletewhere eq" are the exact same package, but when I remove the import above the
deleteWhere
stops working while the
where
is unaffected.
c
Hi @Hildebrandt Tobias This follows changes made in version 0.40.1. Here are the original issues about it for more details about why the changes weren't reverted at the time: GH #1610, #1698. Instead, the consequence of the change was documented retroactively in the changelog; as I believe there was not yet a dedicated breaking changes doc at the time. It would probably be useful to update the appropriate section in our DSL docs page with this import requirement in the interim. It boils down to how the
deleteWhere()
signature is set up differently, compared to
update(where = {})
. To show this, for example, if you defined your own function to match, it would remove any resolution errors:
Copy code
fun <T : Table> T.delete(
    where: SqlExpressionBuilder.() -> Op<Boolean>,
    limit: Int? = null,
): Int {
    val query = DeleteStatement(this, SqlExpressionBuilder.where(), false, limit, emptyList())
    return query.execute(TransactionManager.current()) ?: 0
}

// ... no resolution errors
MyTable.delete(where  = { MyTable.id eq 1 })
> ... and also does not offer any imports. Could you please confirm that this is with IntelliJ IDEA? If you mouse over the error or Show Context Actions (Alt+Enter), do you not get a prompt to
Import extension functions...
?
h
Yes it's the latest stable intelliJ Version 2024.2.4
c
Interesting. I'm seeing the more appropriate prompts with the same version. Could you please confirm whether you have K2 mode enabled? And if so, does disabling K2 mode and restarting then show suggestion of imports? If that's the case, I'll bring up this new development internally.
h
I disabled K2 Mode and then it started suggesting the import:
Also happens with 2024.3 Beta with K2 enabled.
thank you color 1
c
Hi @Hildebrandt Tobias An update: Short of reverting the original feature change mentioned previously, it's not seeming like there's much we can do from the Exposed end. Regardless I've created some new tickets (please consider tracking them if you're interested) and we are trying to bump priority of the issue in the IntelliJ plugin project. EXPOSED-638 KTIJ-32116 Please note that the KTIJ ticket linked above may end up being closed as a duplicate of an original older issue with K2 mode and imports: KTIJ-30186
h
Thank you for your feedback! It's not that big of an issue I just thought I mention it. It's one of those things that can catch someone new by surprise with no obvious way to fix it.
👍 1
c
Hi, sorry for bringing this thread up again, but I just want to share my workaround:
Copy code
fun delete(id: Int): Boolean = Users.deleteWhere {
    with(it) {
      Users.id eq id
    }
  } > 0