DbSetup-kotlin / com.ninja_squad.dbsetup_kotlin / com.ninja_squad.dbsetup.operation.Insert.Builder / repeatingMappedValues

repeatingMappedValues

fun Builder.repeatingMappedValues(vararg entries: Pair<String, Any?>): RowRepeater

Allows inserting the same values multiple times, by specifying them as colum/value pairs instead of a Map.

Example usage:

insertInto("user") {
    columns("id", "firstName", "lastName")
    withGeneratedValue("id", ValueGenerators.sequence())
    repeatingMappedValues("firstName" to "John", "lastName" to "Doe").times(100)
}

This is equivalent to

insertInto("user") {
    columns("id", "firstName", "lastName")
    withGeneratedValue("id", ValueGenerators.sequence())
    repeatingValues(mapOf("firstName" to "John", "lastName" to "Doe")).times(100)
}

but is a bit shorter. Beware to NOT use

insertInto("user") {
    columns("id", "firstName", "lastName")
    withGeneratedValue("id", ValueGenerators.sequence())
    repeatingValues("firstName" to "John", "lastName" to "Doe").times(100)
}

because that would try to insert the Pairs themselves into the table, rather than the values of the pairs.



Parameters

entries - the column/value pairs of the row to insert

Return
the RowRepeater, on which you must call times(N) to specify how many similar rows to insert

Author
JB Nizet