Slick 3 : Compiled queries

313 views
Skip to first unread message

bpo

unread,
May 21, 2015, 7:07:52 PM5/21/15
to scala...@googlegroups.com
Hi,

I try to use Compiled queries with play-slick like explain in doc :  http://slick.typesafe.com/doc/3.0.0/queries.html#compiled-queries

case class Destination(id:Long, name:String)

class Destinations(tag: Tag)
  extends Table[Destination](tag, "destination") {

    def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
    def name = column[String]("name")

    def * = (id, name) <> (Destination.tupled, Destination.unapply)
}

object Destinations extends TableQuery(new Destinations(_)) {

  val findById = Compiled { (id:Rep[Long]) =>
    Destinations.filter(_.id === id)
  }

}

in controller : 

Destinations.findById(1L).result


I am getting the error :  

value result is not a member of slick.lifted.AppliedCompiledFunction[Long,slick.lifted.Query[models.db.Destinations,models.db.Destinations#TableElementType,Seq],Seq[models.db.Destinations#TableElementType]]



Can someone help me ?

virtualeyes

unread,
May 24, 2015, 9:56:23 AM5/24/15
to scala...@googlegroups.com
Following the docs:

def byId(id:Rep[Long]) = Destinations.filter(_.id === id)
def findById = Compiled(byId _)

then call it from controller:
Destinations.findById(1L).result
Reply all
Reply to author
Forward
0 new messages