@@ -32,13 +32,13 @@ import org.ktorm.schema.Column
3232 *
3333 * @property table the table to be inserted.
3434 * @property assignments the inserted column assignments.
35- * @property conflictTarget the index columns on which the conflict may happens.
35+ * @property conflictColumns the index columns on which the conflict may happens.
3636 * @property updateAssignments the updated column assignments while any key conflict exists.
3737 */
3838public data class InsertOrUpdateExpression (
3939 val table : TableExpression ,
4040 val assignments : List <ColumnAssignmentExpression <* >>,
41- val conflictTarget : List <ColumnExpression <* >>,
41+ val conflictColumns : List <ColumnExpression <* >> = emptyList() ,
4242 val updateAssignments : List <ColumnAssignmentExpression <* >> = emptyList(),
4343 override val isLeafNode : Boolean = false ,
4444 override val extraProperties : Map <String , Any > = emptyMap()
@@ -58,7 +58,7 @@ public data class InsertOrUpdateExpression(
5858 * set(it.salary, 1000)
5959 * set(it.hireDate, LocalDate.now())
6060 * set(it.departmentId, 1)
61- * onDuplicateKey {
61+ * onConflict {
6262 * set(it.salary, it.salary + 900)
6363 * }
6464 * }
@@ -85,15 +85,15 @@ public fun <T : BaseTable<*>> Database.insertOrUpdate(
8585 if (primaryKeys.isEmpty() && builder.conflictColumns.isEmpty()) {
8686 val msg =
8787 " Table '$table ' doesn't have a primary key, " +
88- " you must specify the conflict columns when calling onDuplicateKey (col) { .. }"
88+ " you must specify the conflict columns when calling onConflict (col) { .. }"
8989 throw IllegalStateException (msg)
9090 }
9191
9292 val expression = AliasRemover .visit(
9393 InsertOrUpdateExpression (
9494 table = table.asExpression(),
9595 assignments = builder.assignments,
96- conflictTarget = builder.conflictColumns.ifEmpty { primaryKeys }.map { it.asExpression() },
96+ conflictColumns = builder.conflictColumns.ifEmpty { primaryKeys }.map { it.asExpression() },
9797 updateAssignments = builder.updateAssignments
9898 )
9999 )
@@ -124,7 +124,18 @@ public class InsertOrUpdateStatementBuilder : PostgreSqlAssignmentsBuilder() {
124124 /* *
125125 * Specify the update assignments while any key conflict exists.
126126 */
127+ @Deprecated(
128+ message = " This function will be removed in the future, please use onConflict instead" ,
129+ replaceWith = ReplaceWith (" onConflict(columns, block)" )
130+ )
127131 public fun onDuplicateKey (vararg columns : Column <* >, block : AssignmentsBuilder .() -> Unit ) {
132+ onConflict(* columns, block = block)
133+ }
134+
135+ /* *
136+ * Specify the update assignments while any key conflict exists.
137+ */
138+ public fun onConflict (vararg columns : Column <* >, block : AssignmentsBuilder .() -> Unit ) {
128139 val builder = PostgreSqlAssignmentsBuilder ().apply (block)
129140 updateAssignments + = builder.assignments
130141 conflictColumns + = columns
0 commit comments