Skip to content

Commit 64dee20

Browse files
add comment
1 parent 451717d commit 64dee20

File tree

5 files changed

+19
-194
lines changed

5 files changed

+19
-194
lines changed

ktorm-support-sqlite/src/main/kotlin/org/ktorm/support/sqlite/BulkInsert.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -40,6 +40,7 @@ import org.ktorm.schema.ColumnDeclaring
4040
* @property assignments column assignments of the bulk insert statement.
4141
* @property conflictColumns the index columns on which the conflict may happen.
4242
* @property updateAssignments the updated column assignments while key conflict exists.
43+
* @property where the condition whether the update assignments should be executed.
4344
*/
4445
public data class BulkInsertExpression(
4546
val table: TableExpression,
@@ -214,8 +215,8 @@ public open class BulkInsertStatementBuilder<T : BaseTable<*>>(internal val tabl
214215
public class BulkInsertOrUpdateStatementBuilder<T : BaseTable<*>>(table: T) : BulkInsertStatementBuilder<T>(table) {
215216
internal val conflictColumns = ArrayList<Column<*>>()
216217
internal val updateAssignments = ArrayList<ColumnAssignmentExpression<*>>()
217-
internal var where: ColumnDeclaring<Boolean>? = null
218218
internal var doNothing: Boolean = false
219+
internal var where: ColumnDeclaring<Boolean>? = null
219220

220221
/**
221222
* Specify the update assignments while any key conflict exists.
@@ -224,7 +225,7 @@ public class BulkInsertOrUpdateStatementBuilder<T : BaseTable<*>>(table: T) : Bu
224225
val builder = InsertOrUpdateOnConflictClauseBuilder().apply(block)
225226
this.conflictColumns += columns
226227
this.updateAssignments += builder.assignments
227-
this.where = builder.where
228228
this.doNothing = builder.doNothing
229+
this.where = builder.where
229230
}
230231
}

ktorm-support-sqlite/src/main/kotlin/org/ktorm/support/sqlite/Functions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.

ktorm-support-sqlite/src/main/kotlin/org/ktorm/support/sqlite/Global.kt

Lines changed: 0 additions & 159 deletions
This file was deleted.

ktorm-support-sqlite/src/main/kotlin/org/ktorm/support/sqlite/InsertOrUpdate.kt

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
*/
3637
public 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() {
133134
public 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
166156
public 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
/**

ktorm-support-sqlite/src/test/kotlin/org/ktorm/support/sqlite/CommonTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class CommonTest : BaseSQLiteTest() {
7878
set(it.hireDate, LocalDate.now())
7979
set(it.departmentId, 1)
8080
onConflict {
81-
setExcluded(it.salary)
81+
set(it.salary, excluded(it.salary))
8282
}
8383
}
8484
database.insertOrUpdate(Employees.aliased("t")) {

0 commit comments

Comments
 (0)