【发布时间】:2020-06-25 16:41:36
【问题描述】:
我在一个新项目中使用 Exposed,我注意到对于插入和更新语句,我必须复制记录值的所有分配。
一个例子:
val orderId = Orders.insert {
it[orderType] = orderDTO.orderType
it[deliveryDateTime] = LocalDateTime.of(
LocalDate.parse(orderDTO.deliveryDate),
LocalTime.parse(orderDTO.deliveryTime)
)
it[customerName] = orderDTO.customerName
it[customerPhone] = orderDTO.customerPhone
it[customerAddress] = orderDTO.customerAddress
// ... other fields
} get Orders.id
Orders.update({ Orders.id eq orderId }) {
it[orderType] = orderDTO.orderType
it[deliveryDateTime] = LocalDateTime.of(
LocalDate.parse(orderDTO.deliveryDate),
LocalTime.parse(orderDTO.deliveryTime)
)
it[customerName] = orderDTO.customerName
it[customerPhone] = orderDTO.customerPhone
it[customerAddress] = orderDTO.customerAddress
// ... other fields
}
我正在尝试提取 lambda 或函数中的常见分配,但在第一种情况下,主体的类型是 T.(InsertStatement<Number>)->Unit,而在更新中它是 T.(UpdateStatement)->Unit,所以我看不到简单的实现这一目标的方法。
是我遗漏了什么还是设计使然?
【问题讨论】:
标签: kotlin kotlin-exposed