Skip to content

Commit 0055d27

Browse files
refactor
1 parent 140c900 commit 0055d27

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ public fun <T : BaseTable<*>> Database.bulkInsertOrUpdate(
143143
): Int {
144144
val builder = BulkInsertOrUpdateStatementBuilder(table).apply { block(table) }
145145

146-
val primaryKeys = table.primaryKeys
147-
if (primaryKeys.isEmpty() && builder.conflictColumns.isEmpty()) {
146+
val conflictColumns = builder.conflictColumns.ifEmpty { table.primaryKeys }
147+
if (conflictColumns.isEmpty()) {
148148
val msg =
149149
"Table '$table' doesn't have a primary key, " +
150150
"you must specify the conflict columns when calling onConflict(col) { .. }"
@@ -154,7 +154,7 @@ public fun <T : BaseTable<*>> Database.bulkInsertOrUpdate(
154154
val expression = BulkInsertExpression(
155155
table = table.asExpression(),
156156
assignments = builder.assignments,
157-
conflictColumns = builder.conflictColumns.ifEmpty { primaryKeys }.map { it.asExpression() },
157+
conflictColumns = conflictColumns.map { it.asExpression() },
158158
updateAssignments = builder.updateAssignments
159159
)
160160

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public fun <T : BaseTable<*>> Database.insertOrUpdate(
8181
): Int {
8282
val builder = InsertOrUpdateStatementBuilder().apply { block(table) }
8383

84-
val primaryKeys = table.primaryKeys
85-
if (primaryKeys.isEmpty() && builder.conflictColumns.isEmpty()) {
84+
val conflictColumns = builder.conflictColumns.ifEmpty { table.primaryKeys }
85+
if (conflictColumns.isEmpty()) {
8686
val msg =
8787
"Table '$table' doesn't have a primary key, " +
8888
"you must specify the conflict columns when calling onConflict(col) { .. }"
@@ -92,7 +92,7 @@ public fun <T : BaseTable<*>> Database.insertOrUpdate(
9292
val expression = InsertOrUpdateExpression(
9393
table = table.asExpression(),
9494
assignments = builder.assignments,
95-
conflictColumns = builder.conflictColumns.ifEmpty { primaryKeys }.map { it.asExpression() },
95+
conflictColumns = conflictColumns.map { it.asExpression() },
9696
updateAssignments = builder.updateAssignments
9797
)
9898

0 commit comments

Comments
 (0)