Skip to main content

Values clauses

From rows

val fakeShop = rowOf(
ShopTable.name setTo "Fake Shop",
ShopTable.address setTo "79 Fake Street, Fakesville"
)

val result = values(fakeShop)
.perform(db)
.single()

check("Fake Shop" == result[ShopTable.name])

From a collection

val names = listOf("Dylan", "Santiago", "Chloe")

val customers = values(names) { name ->
this[CustomerTable.name] = name
this[CustomerTable.shop] = groceryStoreId
this[CustomerTable.spent] = BigDecimal("10.80")
}

CustomerTable
.insert(customers)
.perform(db)

Using labels

val name = label<String>("name")
val age = label<Int>("age")

val names = values(listOf("Jeremy", "Sofia")) {
this[name] = it
this[age] = 29
}

val (firstName, firstAge) = names
.subquery()
.orderBy(name.desc())
.select(upper(name) as_ name, age)
.perform(db)
.first()

check(firstName == "SOFIA")
check(firstAge == 29)