kotlin - 使用另一个列值 [Exposed Kotlin] 更新表列

标签 kotlin postgresql-9.4 kotlin-exposed

公开版本:0.28.1

Kotlin 版本:1.5.0

数据库:PostgreSQL 9.4

您好,我是 Exposed ORM Framework 的新手。 我需要用同一个表中的另一个列值更新一个表列值,这两个列类型是日期时间。 在 PostgreSQL 上会是这样的:

update order_details set production_date = current_timestamp - registry_date 

如何在 Exposed ORM 上执行此操作? 这是我的实体:

object OrderDetails : Table (name = "detalle_orden") {
    val id = integer("id").autoIncrement("detalle_orden_id_seq")
    val sellDetail = integer("detalle_venta").references(SellDetails.id)
    val order = integer("orden")
    val registryDate = datetime("fecha_registro")
    val registryHour = varchar("hora_registro", 30).nullable()
    val productionDate = datetime("fecha_produccion").nullable()
    val productionHour = varchar("hora_produccion", 30).nullable()
    val finishedDate = datetime("fecha_terminado").nullable()
    val finishedHour = varchar("hora_terminado", 30).nullable()
    val deliveryDate = datetime("fecha_entregado").nullable()
    val deliveryHour = varchar("hora_entregado",30).nullable()
    val observations = varchar("observaciones", 500)

    override val primaryKey = PrimaryKey(id, name = "detalle_orden_pkey")
}

最佳答案

作为Tapac said in comments ,这个用例在 wiki 中:https://github.com/JetBrains/Exposed/wiki/DSL#update

OrderDetails.update({ OrderDetails.id eq 8 }) {
    with(SqlExpressionBuilder) {
       it.update(OrderDetails.productionDate, OrderDetails.registryDate + OffsetDateTime.now())
       // or 
       it[OrderDetails.productionDate] = OrderDetails.registryDate + OffsetDateTime.now())
    }
} 

关于kotlin - 使用另一个列值 [Exposed Kotlin] 更新表列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69302486/

相关文章:

kotlin - 在 Kotlin 中只返回 null 的函数

arrays - Postgres 9.4 按 json 数组的元素值选择

postgresql - WAL 文件来自不同的数据库系统

kotlin - 如何进行批量更新?

kotlin-exposed - 如何在 Kotlin Exposed 的一对多关系中设置级联类型?

java - 如何在 Intellij 中将 Kotlin 与 H2 和 SQLite 结合使用

android - 如何解决在直接将图像从 android 库共享到我的 flutter 应用程序时收到的奇怪和不完整的 Uri 和路径

安卓 Kotlin : BuildConfig file isn't giving the correct value

android - 当我构建我的应用程序时,如果它们属于另一个模块,导入将成为未解析的引用

postgresql - PostgreSQL 9.4 中的流式复制