简体   繁体   中英

Scala Slick Comprehension issues

I have the following in a library:

Case Class:

case class Foo(
  id: Option[Long],
  bar: Long
...
)

Table:

object Foos extends Mapper[Foo]("foo"){ //I'm using slick-inegration so the id is free
  def bar = column[Long]("bar")
  def cols = bar ~ ...
  def * = id.? ~: cols <> (Foo, Foo.unapply _)
  def returningId = cols returning id
  def insert(f: Foo)(implicit s: Session) = returningId.insert(Generic[Foo].to(f).tail.tupled)

...
}

The data access layer is set up in the binary that utilizes these models. If I try a comprehension such as "for(f<-Foos) yield f", inside of the Foos definition, we're happy. If I try it anywhere in the codebase which uses this library, I get:

value map is not a member of object DB.this.Foos

My guess is it's not getting lifted into a Query, but I'm not entirely sure. Any clarity would be appreciated.

Try doing:

  import slick.driver.MySQLDriver.simple._

or whichever driver it is that you need. You'll need the implicit classes in there to provide the map 'extension' method on Foos .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM