Lift の Mapper を使用する必要があります (Scala にはもっと優れた ORM があるかもしれませんが、これは今すぐ変更できるものではありません)。通常、Mapper では、テーブルは次のように定義されます。
package com.sample.model
import net.liftweb.mapper._
class Table extends LongKeyedMapper[Table] with IdPK {
def getSingleton = Table
object other_table_id extends MappedLongForeignKey(this, OtherTable)
object date_field extends MappedDate(this)
object string_field extends MappedString(this, 255)
def toCaseClass = ...
}
object Table extends Table with LongKeyedMetaMapper[Table]
ここで、レコードをより簡単に操作するために Table のケース クラスを定義したいと思います。Mapper はあまり「Scala 慣用的」ではなく、タイプ セーフでもなく、間違いなく不変でもないからです。私のケースクラスは次のようになります。
case class TableCC(id: Long, otherTableId: Long, dateField: Option[Date], ...) {
def toMapper = ...
}
ケース クラスの名前と配置場所を教えてください。
- 別の名前 (TableCC または TableCaseClass) の com.sample.model では?
- 同じ名前 (テーブル) の別のパッケージ (例: com.sample.model.caseclass) で?
- テーブル オブジェクトでは?
- ...?