How can I omit case class fields in a slick table mapping?

前端 未结 1 1330
清酒与你
清酒与你 2021-02-08 11:23

I\'m teaching myself some Scala and am currently getting my feet wet with slick (3.1) + play framework, so maybe the answer is simple here and I\'m missing something obvious. I

1条回答
  •  孤城傲影
    2021-02-08 11:38

    Your trouble here is your constructUser is function of 4 parameters, while it supposed to be function of single Tuple4

    Try to add type signatures.
    This sample works for instance ( some simplifications included )

    type Data = (Long, String, String, Option[String])
    
    def constructUser: Data => User = {
      case (id, username, passwordHash, email) => User(id, username, passwordHash, email)
    
    }
    def extractUser: PartialFunction[User, Data] = {
      case User(id, username, passwordHash, email, _, _) =>
        (id, username, passwordHash, email)
    }
    
    def * = (id, username, passwordHash, email) <> (constructUser, extractUser.lift)
    

    0 讨论(0)
提交回复
热议问题