나는 훌륭한 ScalaQuery를 사용하고 있으며 일반 작업을위한 일반 저장소를 만들려고 노력하고 있습니다. 희망을 갖고 누군가가 도울 수 있기를 바랍니다.ScalaQuery를 사용하는 일반 저장소
나는 제품 및 주문에 대한 구조
abstract class Record(id : Int)
class Product(id: Int,name:String,price : Int) extends Record(id)
class Order(id: Int,name:String,amount: Int) extends Record(id)
및 견인 테이블에 다음과 같은 예를 들어 있습니다. 테이블을 설명하는 튜플이 특성에 컴파일 시간 (또는 추상 클래스) RecordRepository에 알려져 있지 않기 때문에
trait RecordRepository[T <: ExtendedTable[O]]{
findById(id:Int) : Option[T]
findAll() : List[T]
save(entity:T)
...
}
class ProductRepository extends RecordRepository[Product]
class ProductRepository extends RecordRepository[Order]
object ProductTable extends ExtendedTable[(Long, String, Int)]("product") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name", O.NotNull)
def price = column[Int]("price", O.NotNull)
def * = id ~ name ~ price
}
object OrderTable extends ExtendedTable[(Long, String, Int)]("order") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name", O.NotNull)
def amount = column[Int]("price", O.NotNull)
def * = id ~ name ~ amount
}
내가, 이해의를 사용하여 querys를 구현할 수 없습니다 : 지금은 일반 저장소를 원한다.
미리 감사드립니다.
제공된 코드를 기반으로, 아직 해당 DB 테이블 – virtualeyes
을에 제품 및 주문 모델 클래스를 매핑하지 않은 네, 공간을 절약하고 싶습니다. 여기 간단한 스키마가 있습니다 : 'Product ProductTable extends ExtendedTable [(Long, String, Int)] ("product") { def id = column [Long] ("id", O. PrimaryKey, O.AutoInc) def name = column [문자열] ("이름", O.) 개체 OrderTable은 ExtendedTable [(Long, String, Int)] ("order")을 확장합니다. { def amount = column [Int] ("price", "O.PrimaryKey", "O.AutoInc") :def id = ", O.NotNull) def * = id ~ name ~ 금액 } ' – singy