Skip to content

Commit

Permalink
feat: EXPOSED-435 Allow insertReturning() to set isIgnore = true
Browse files Browse the repository at this point in the history
Rename new parameter to ignoreErrors
  • Loading branch information
bog-walk committed Jul 8, 2024
1 parent 6cb6e84 commit fa67612
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,18 @@ fun <T : Table> 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.
* @sample org.jetbrains.exposed.sql.tests.shared.dml.ReturningTests.testInsertReturning
*/
fun <T : Table> T.insertReturning(
returning: List<Expression<*>> = columns,
ignore: Boolean = false,
ignoreErrors: Boolean = false,
body: T.(InsertStatement<Number>) -> Unit
): ReturningStatement {
val insert = InsertStatement<Number>(this, ignore)
val insert = InsertStatement<Number>(this, ignoreErrors)
body(insert)
return ReturningStatement(this, returning, insert)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit fa67612

Please sign in to comment.