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

com.sxtanna.db.struct.statement.update.kt Maven / Gradle / Ivy

There is a newer version: 1.6
Show newest version
package com.sxtanna.db.struct.statement

import com.sxtanna.db.ext.Value
import com.sxtanna.db.struct.Table
import com.sxtanna.db.type.Executed
import com.sxtanna.db.type.Targeted
import kotlin.internal.OnlyInputTypes
import kotlin.reflect.KProperty1

/**
 * Describes an SQL "UPDATE" statement
 */
interface Update : Executed, Targeted, T> {

    /**
     * Set this column to this value
     */
    fun <@OnlyInputTypes R : Any?> set(column : KProperty1, value : R) : Update

}


/**
 * An object that can update rows and columns in a table
 */
interface DBUpdater {

    /**
     * Create an update statement for this table
     *  * Execute statement either by calling [Update.execute]
     *  * or
     *  * Returning it from a Kuery#invoke block
     */
    fun  update(table : Table) : Update

    /**
     * Update the supplied rows in this table
     *  * Executed automatically
     */
    fun  update(table : Table, vararg rows : T) {
        update(table, rows.toList())
    }

    /**
     * Update the supplied rows in this table
     *  * Executed automatically
     */
    fun  update(table : Table, rows : Collection)

    /**
     * Create an update statement that updates the supplied columns in this table
     *  * Execute statement either by calling [Update.execute]
     *  * or
     *  * Returning it from a Kuery#invoke block
     */
    fun  update(table : Table, vararg values : Value) : Update {
        val update = update(table)
        values.forEach { update.set(it.prop, it.value) }

        return update
    }

    /**
     * Update all rows in this table to this row
     *  * Executed automatically
     *  * Does not work on tables with primary keys
     */
    fun  updateAllRows(table : Table, row : T)

    /**
     * Update all rows in this table to these values
     *  * Executed automatically
     *  * Cannot set the value of a primary key
     */
    fun  updateAllRows(table : Table, vararg values : Value)


    /**
     * An object that can update rows and columns in its table
     */
    interface TableUpdater {

        /**
         * @see [DBUpdater.update]
         */
        fun update() : Update

        /**
         * Updater.update(table : Table<T>, vararg rows : T)
         *
         * @sample [Cannot_link_to_specific_method][update]
         */
        fun update(vararg rows : T) {
            update(rows.toList())
        }

        /**
         * Updater.update(table : Table, rows : Collection)
         *
         * @sample [Cannot_link_to_specific_method][update]
         */
        fun update(rows : Collection)

        /**
         * Updater.update(table : Table<T>, vararg values : Value<T, *>)
         *
         * @sample [Cannot_link_to_specific_method][update]
         */
        fun update(vararg values : Value) : Update

        /**
         * @see [DBUpdater.updateAllRows]
         */
        fun updateAllRows(row : T)

        /**
         * Updater.updateAllRows(table : Table<T>, vararg values : Value<T, *>)
         *
         * @sample [Cannot_link_to_specific_method][updateAllRows]
         */
        fun updateAllRows(vararg values : Value)

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy