All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.exposed.sql.statements.DeleteStatement.kt Maven / Gradle / Ivy

There is a newer version: 0.17.14
Show newest version
package org.jetbrains.exposed.sql.statements

import org.jetbrains.exposed.sql.*
import java.sql.PreparedStatement

open class DeleteStatement(val table: Table, val where: Op? = null, val isIgnore: Boolean = false, val limit: Int? = null, val offset: Int? = null): Statement(StatementType.DELETE, listOf(table)) {

    override fun PreparedStatement.executeInternal(transaction: Transaction): Int {
        transaction.flushCache()
        transaction.entityCache.removeTablesReferrers(listOf(table))
        return executeUpdate()
    }

    override fun prepareSQL(transaction: Transaction): String =
        transaction.db.dialect.functionProvider.delete(isIgnore, table, where?.let { QueryBuilder(true).append(it).toString() }, limit, transaction)

    override fun arguments(): Iterable>> = QueryBuilder(true).run {
        where?.toQueryBuilder(this)
        listOf(args)
    }

    companion object {
        fun where(transaction: Transaction, table: Table, op: Op, isIgnore: Boolean = false, limit: Int? = null, offset: Int? = null): Int
            = DeleteStatement(table, op, isIgnore, limit, offset).execute(transaction) ?: 0

        fun all(transaction: Transaction, table: Table): Int = DeleteStatement(table).execute(transaction) ?: 0
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy