Values clauses
From rows
- Kotlin
- SQL
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])
VALUES ('Fake Shop', '79 Fake Street, Fakesville')
From a collection
- Kotlin
- SQL
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)
INSERT INTO "Customer"("name", "shop", "spent")
VALUES ('Dylan', 2, 10.80)
, ('Santiago', 2, 10.80)
, ('Chloe', 2, 10.80)
Using labels
- Kotlin
- SQL
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)
SELECT UPPER(T0."name") "name"
, T0."age"
FROM (VALUES ('Jeremy', 29)
, ('Sofia', 29)) T0("name", "age")
ORDER BY T0."name" DESC