이해력이있는 부분이 있습니다. 여기에 사용 된 객체가 자동으로 slick.codegen.SourceCodeGenerator으로 DB에서 생성 된 :TableQuery to case 클래스
for {
boxer <- Boxers.filter { b => b.address === someAddress }
fullBoxer <- buildFullBoxer(boxer)
} yield {
fullBoxer
}
buildFullBoxer 기능은 루프가 컴파일되지 않도록 매개 변수로 케이스 클래스 BoxersRow을 소요하고 오류 발생 :
을type mismatch; found : models.Tables.Boxers required: models.Tables.BoxersRow
생성 된 스키마 코드는 다음과 같습니다
물론case class BoxersRow(id: Long, firstName: String, lastName: String, nick: Option[String] = None, boxingTypeId: Int = 0, birthDate: Option[java.sql.Date] = None, address: Option[String] = None, lastUpdated: java.sql.Timestamp)
implicit def GetResultBoxersRow(implicit e0: GR[Long], e1: GR[String], e2: GR[Option[String]], e3: GR[Int], e4: GR[Option[java.sql.Date]], e5: GR[java.sql.Timestamp]): GR[BoxersRow] = GR{
prs => import prs._
BoxersRow.tupled((<<[Long], <<[String], <<[String], <<?[String], <<[Int], <<?[java.sql.Date], <<?[String], <<[java.sql.Timestamp]))
}
class Boxers(_tableTag: Tag) extends Table[BoxersRow](_tableTag, "boxers") {
def * = (id, firstName, lastName, nick, boxingTypeId, birthDate, address, lastUpdated) <> (BoxersRow.tupled, BoxersRow.unapply)
def ? = (Rep.Some(id), Rep.Some(firstName), Rep.Some(lastName), nick, Rep.Some(boxingTypeId), birthDate, address, Rep.Some(lastUpdated)).shaped.<>({r=>import r._; _1.map(_=> BoxersRow.tupled((_1.get, _2.get, _3.get, _4, _5.get, _6, _7, _8.get)))}, (_:Any) => throw new Exception("Inserting into ? projection not supported."))
val id: Rep[Long] = column[Long]("id", O.AutoInc, O.PrimaryKey)
....
}
lazy val Boxers = new TableQuery(tag => new Boxers(tag))
것은 내가 자동으로 GE를 변경하려면 않을 것 필수 스키마 개체 buildFullBoxer 함수는 DB에서 추가 데이터를 읽고 필요한 모든 데이터를 포함하는 공통 FullBoxer 객체를 만듭니다.
private def buildFullBoxer(boxersRow: BoxersRow): DBIO[FullBoxer] = {
val query = for {
((((boxer, fight), division), b1), b2) <-
Boxers.filter(_.id === boxersRow.id)
.joinLeft(Fights).on((b, f) => (b.id === f.firstBoxerId) || (b.id === f.secondBoxerId))
.joinLeft(Divisions).on((bf, d) => bf._2.map { _.divisionId === d.id })
.joinLeft(Boxers).on((bfd, b1) => bfd._1._2.map { _.firstBoxerId === b1.id })
.joinLeft(Boxers).on((bfdb1, b2) => bfdb1._1._1._2.map { _.secondBoxerId === b2.id })
} yield (boxer, fight, division, b1, b2)
val action = query.result.map {case sequence => sequence.groupBy(x => x._1) }.
map { _.map { case (box, tup) => (box, tup.map { case (b, f, d, b1, b2) => f.map { fight => (fight, d.getOrElse(throw NoDivisionException("No such a division: " + fight.divisionId)), b1.getOrElse(throw NoBoxerException("No boxer with id " + fight.firstBoxerId, Seq.empty, None)), b2.getOrElse(throw NoBoxerException("No boxer with id " + fight.secondBoxerId, Seq.empty, None)), Seq.empty) } } map (_.map(FullFight.tupled)) flatten) } toSeq }.
map {_.map(FullBoxer.tupled).head }
action
}
어떻게하면 이해할 수있는 루프를 위해 buildFullBoxer 함수로 사례 클래스 BoxersRow를 전달할 수 있습니까?
감사합니다.
답장을 보내 주셔서 감사합니다 :) 그것은 작동합니다! – Gandalf