11/*
2- * Copyright 2018-2021 the original author or authors.
2+ * Copyright 2018-2022 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import org.ktorm.schema.ColumnDeclaring
3232 * @property assignments the inserted column assignments.
3333 * @property conflictColumns the index columns on which the conflict may happen.
3434 * @property updateAssignments the updated column assignments while any key conflict exists.
35+ * @property where the condition whether the update assignments should be executed.
3536 */
3637public data class InsertOrUpdateExpression (
3738 val table : TableExpression ,
@@ -109,8 +110,8 @@ private fun <T : BaseTable<*>> buildInsertOrUpdateExpression(
109110 table = table.asExpression(),
110111 assignments = builder.assignments,
111112 conflictColumns = conflictColumns.map { it.asExpression() },
112- where = builder.where?.asExpression() ,
113- updateAssignments = if ( builder.doNothing) emptyList() else builder.updateAssignments
113+ updateAssignments = if ( builder.doNothing) emptyList() else builder.updateAssignments ,
114+ where = builder.where?.asExpression()
114115 )
115116}
116117
@@ -133,19 +134,8 @@ public open class SQLiteAssignmentsBuilder : AssignmentsBuilder() {
133134public class InsertOrUpdateStatementBuilder : SQLiteAssignmentsBuilder () {
134135 internal val conflictColumns = ArrayList <Column <* >>()
135136 internal val updateAssignments = ArrayList <ColumnAssignmentExpression <* >>()
136- internal var where: ColumnDeclaring <Boolean >? = null
137137 internal var doNothing = false
138-
139- /* *
140- * Specify the update assignments while any key conflict exists.
141- */
142- @Deprecated(
143- message = " This function will be removed in the future, please use onConflict { } instead" ,
144- replaceWith = ReplaceWith (" onConflict(columns, block)" )
145- )
146- public fun onDuplicateKey (vararg columns : Column <* >, block : AssignmentsBuilder .() -> Unit ) {
147- onConflict(* columns, block = block)
148- }
138+ internal var where: ColumnDeclaring <Boolean >? = null
149139
150140 /* *
151141 * Specify the update assignments while any key conflict exists.
@@ -154,8 +144,8 @@ public class InsertOrUpdateStatementBuilder : SQLiteAssignmentsBuilder() {
154144 val builder = InsertOrUpdateOnConflictClauseBuilder ().apply (block)
155145 this .conflictColumns + = columns
156146 this .updateAssignments + = builder.assignments
157- this .where = builder.where
158147 this .doNothing = builder.doNothing
148+ this .where = builder.where
159149 }
160150}
161151
@@ -164,21 +154,21 @@ public class InsertOrUpdateStatementBuilder : SQLiteAssignmentsBuilder() {
164154 */
165155@KtormDsl
166156public class InsertOrUpdateOnConflictClauseBuilder : SQLiteAssignmentsBuilder () {
167- internal var where: ColumnDeclaring <Boolean >? = null
168157 internal var doNothing = false
158+ internal var where: ColumnDeclaring <Boolean >? = null
169159
170160 /* *
171- * Specify the where clause for this update statement .
161+ * Explicitly tells ktorm to ignore any on-conflict errors and continue insertion .
172162 */
173- public fun where ( block : () -> ColumnDeclaring < Boolean > ) {
174- this .where = block()
163+ public fun doNothing ( ) {
164+ this .doNothing = true
175165 }
176166
177167 /* *
178- * Explicitly tells ktorm to ignore any on-conflict errors and continue insertion .
168+ * Specify the where condition for the update clause .
179169 */
180- public fun doNothing ( ) {
181- this .doNothing = true
170+ public fun where ( block : () -> ColumnDeclaring < Boolean > ) {
171+ this .where = block()
182172 }
183173
184174 /* *
@@ -192,13 +182,6 @@ public class InsertOrUpdateOnConflictClauseBuilder : SQLiteAssignmentsBuilder()
192182 sqlType = column.sqlType
193183 )
194184 }
195-
196- /* *
197- * be equal to 'set(column, excluded(column))'.
198- */
199- public fun <T : Any > setExcluded (column : Column <T >) {
200- set(column, excluded(column))
201- }
202185}
203186
204187/* *
0 commit comments