【发布时间】:2016-09-17 01:15:36
【问题描述】:
我的模型上有一个更新方法,它接受一个带有选项类型的类,我想构造一个更新语句,其中包括一个动态 SET,具体取决于哪些字段具有值。使用 Phanton-dsl 1.5 我有类似的东西;
import com.websudos.phantom.query.{ AssignmentsQuery => AQ }
override def updateModel(m: Upd)(implicit ec: EC): Future[Unit] = {
if (m.isEmpty) return Future.successful(())
val upd = update
upd.where(_.user_id eqs m.user_id)
val mod: AQ[CTable, Val] = new AQ(this, upd.qb.`with`())
for (first_name <- m.first_name) mod.and(_.first_name setTo first_name)
for (last_name <- m.last_name) mod.and(_.last_name setTo last_name)
mod.future.map(_ => ())
}
现在我正在尝试迁移到 Phantom-dsl (1.27) 的最新版本,但我无法仅使用 dsl 进行等效操作。由于任何字段都可能为 None,因此构造第一个 modify() 然后使用任意数量的 and() 进行该操作被证明是困难的。
任何有关如何处理此问题的建议都会有所帮助。
【问题讨论】:
标签: scala phantom-dsl