def cond[A](value: A)(f: PartialFunction[A, SQLBuilder => SQLBuilder]): SQLBuilderこんな感じの(実際にはSQLBuilderはサブクラス型にしないとだけど)あれば下みたいに書けるかなー
val id: Option[Int] = ...
val name: Option[String] = ...
select(c.*)
.from(Customer as c)
.where
.cond(id) { case Some(i) => _.eq(c.id, i) }
.and
.cond(name) { case Some(n) => _.eq(c.name, n) }と思うけど、 .where とか .and とかはどうしょうもなくてぐぬぬ
dynamicAndConditions / dynamicOrConditions という名前なら私はそんなに違和感ないですね。
https://github.com/seratch/scalikejdbc/blob/feature/dynamic-conditions/scalikejdbc-interpolation/src/test/scala/scalikejdbc/QueryInterfaceSpec.scala#L126-L177