【问题标题】:How to do batch updates?如何进行批量更新?
【发布时间】:2018-06-25 00:34:19
【问题描述】:

我正在尝试使用 Exposed 更新 MySql 中行列表中的特定列。

其实Exposed支持batchInsert,但是没有类似batchUpdate的东西,有什么解决办法吗?

注意:该表不是IdTable

【问题讨论】:

  • 你在使用 Room 吗?
  • 不,只是暴露的 kotlin

标签: kotlin sql-update kotlin-exposed


【解决方案1】:

有与 IdTables 一起使用的 BatchUpdateStatement。

val yourData = listOf<DataToUpdate>()
BatchUpdateStatement(FooTable).apply {
    yourData.forEach {
        addBatch(it.id)
        this[FooTable.name] = it.name
        this[FooTable.column] = it.field
    }
    execute(Transaction.current())
}

【讨论】:

  • 实际上该表不是 IdTable
  • 那么无法进行批量更新,因为Exposed无法确定每次更新的身份条件。
猜你喜欢
  • 1970-01-01
  • 2018-04-01
  • 2012-09-21
  • 2020-07-10
  • 1970-01-01
  • 2016-08-15
  • 2012-08-23
  • 1970-01-01
相关资源
最近更新 更多