1

I have following problem - there is sql with DECODE oracle function:

SELECT u.URLTYPE, u.URL
  FROM KAA.ENTITYURLS u
JOIN KAA.ENTITY e 
  ON decode(e.isurlconfigured, 0, e.urlparentcode, 1, e.CODE, 
    NULL)=u.ENTITYCODE
JOIN CASINO.Casinos c ON e.casinocode = c.code
             WHERE e.NAME = $entityName
             AND C.NAME = $casinoName

I'm trying to realize this sql in my slick code , like:

val queryUrlsEntityName = for {
 entityUrl <- entityUrls
 entity <- entities.filter(e => e.name.trim===entityName &&
      entityUrl.entityCode.asColumnOf[Option[Int]]==(e.isURLConfigured match 
         { 
           case Some(0) => e.urlParentCode
           case Some(1) => e.code.asColumnOf[Option[Int]]
           case _ => None
         }
           )
       )
       casino <- casinos.filter(_.name.trim===casinoName) if 
 entity.casinoCode==casino.code
      } yield (entityUrl)

But I don't understand how can I implement of matching of values in line

case Some(0) => e.urlParentCode

because I'm getting error

  constructor cannot be instantiated to expected type;
  [error]  found   : Some[A]
  [error]  required: slick.lifted.Rep[Option[Int]]
  [error]            case Some(0) => e.urlParentCode

Thanks for any advice

1 Answers1

0

You should rewrite your code in pattern-matching section so you could compare required Rep[Option[Int]] - to left type, in your case it's Option[Int], or transform Rep[Option[Int]] to Option[Int] type. Rep is only the replacement to the column datatype in slick. I would prefer the first variant - this answer shows how to make the transformation from Rep, or you can use map directly:

map(u => (u.someField)).result.map(_.headOption.match { 
  case Some(0) => .....
})
  • Thank you very much! I've changed my code to: `entityUrl.entityCode.asColumnOf[Option[Int]] == e.isURLConfigured.result.map(_ match { case Some(0) => e.urlParentCode case Some(1) => e.code.asColumnOf[Option[Int]] case _ => None } )` Looks like it's working.. – Vladimir Lubenchenko Aug 02 '17 at 11:17
  • @Vladimir Lubenchenko if it was helpful, please approve my answer –  Aug 02 '17 at 11:34
  • Sorry, I've tried to approve your answer, but unsuccessfully. Error is "Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score" – Vladimir Lubenchenko Aug 03 '17 at 14:38