From fa67612e32be3ac1a819004e9fef371924d0a19f Mon Sep 17 00:00:00 2001 From: Chantal Loncle <82039410+bog-walk@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:44:21 -0400 Subject: [PATCH] feat: EXPOSED-435 Allow insertReturning() to set isIgnore = true Rename new parameter to ignoreErrors --- .../src/main/kotlin/org/jetbrains/exposed/sql/Queries.kt | 6 +++--- .../exposed/sql/tests/shared/dml/ReturningTests.kt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Queries.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Queries.kt index 611079e030..d849126e34 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Queries.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Queries.kt @@ -391,7 +391,7 @@ fun T.insertIgnore( * Represents the SQL statement that inserts new rows into a table and returns specified data from the inserted rows. * * @param returning Columns and expressions to include in the returned data. This defaults to all columns in the table. - * @param ignore Whether to ignore any possible errors that occur during the process. + * @param ignoreErrors Whether to ignore any possible errors that occur during the process. * Note `INSERT IGNORE` is not supported by all vendors. Please check the documentation. * @return A [ReturningStatement] that will be executed once iterated over, providing [ResultRow]s containing the specified * expressions mapped to their resulting data. @@ -399,10 +399,10 @@ fun T.insertIgnore( */ fun T.insertReturning( returning: List> = columns, - ignore: Boolean = false, + ignoreErrors: Boolean = false, body: T.(InsertStatement) -> Unit ): ReturningStatement { - val insert = InsertStatement(this, ignore) + val insert = InsertStatement(this, ignoreErrors) body(insert) return ReturningStatement(this, returning, insert) } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/ReturningTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/ReturningTests.kt index b1aea9783f..225d64e9fc 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/ReturningTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/ReturningTests.kt @@ -61,14 +61,14 @@ class ReturningTests : DatabaseTestsBase() { assertEquals(1, tester.selectAll().count()) // no result set is returned because insert is ignored - val resultWithConflict = tester.insertReturning(ignore = true) { + val resultWithConflict = tester.insertReturning(ignoreErrors = true) { it[item] = "Item A" }.toList() assertTrue { resultWithConflict.isEmpty() } assertEquals(1, tester.selectAll().count()) - val resultWithoutConflict = tester.insertReturning(ignore = true) { + val resultWithoutConflict = tester.insertReturning(ignoreErrors = true) { it[item] = "Item B" }.single()