kotlin-orm / ktorm

A lightweight ORM framework for Kotlin with strong-typed SQL DSL and sequence APIs.
https://www.ktorm.org
Apache License 2.0
2.15k stars 147 forks source link

如何在删除数据时使用limit #443

Closed cnyy99 closed 1 year ago

cnyy99 commented 2 years ago
/**
     * Delete records that satisfy the given [predicate].
     */
    open fun deleteIf(predicate: (T) -> ColumnDeclaring<Boolean>, limit: Int? = null): Int {
        var seq = database.sequenceOf(tableObject)
        limit?.let { seq = seq.take(limit) }
        return seq.removeIf(predicate)
    }

使用时会报错

java.lang.UnsupportedOperationException: Entity manipulation functions are not supported by this sequence object. Please call on the origin sequence returned from database.sequenceOf(table)
    at org.ktorm.entity.EntityDmlKt.checkForDml(EntityDml.kt:217) ~[ktorm-core-3.5.0.jar:na]
    at org.ktorm.entity.EntityDmlKt.removeIf(EntityDml.kt:135) ~[ktorm-core-3.5.0.jar:na]
    at com.kuaishou.videoqa.kperf.db.mysql.BaseDao.deleteIf(BaseDao.kt:51) ~[classes/:na]
vincentlauvlwj commented 2 years ago

不支持这种写法