case class Seat(id: Int, code: String, observation: Option[String])
class Seats(tag: Tag) extends Table[Seat](tag, "seats") {
def id = column[Int]("id", O.PrimaryKey)
def code = column[String]("code")
def observation = column[Option[String]]("observation")
def * = (id, code, observation) <> (Seat.tupled, Seat.unapply)
}
val seats = TableQuery[Seats]
seats.filter(_.observation === None)
def findAllSeatsWithoutObservation = {
db.run(seats.filter(_.observation === None).result)
}
Hi,
Please, consider code below.case class Seat(id: Int, code: String, observation: Option[String])class Seats(tag: Tag) extends Table[Seat](tag, "seats") {
def id = column[Int]("id", O.PrimaryKey)
def code = column[String]("code")
def observation = column[Option[String]]("observation")
def * = (id, code, observation) <> (Seat.tupled, Seat.unapply)
}val seats = TableQuery[Seats]
How must I code the query "find all seats with no observation"? Compiler doesn't accept thisseats.filter(_.observation === None)
I wish create a method like thisdef findAllSeatsWithoutObservation = {
db.run(seats.filter(_.observation === None).result)
}
Thanks,--
Leandro
---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/6d878d3c-57d4-404d-b40f-02b8c63bc970%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Wed, May 27, 2015, 3:06 PM Leandro Komosinski <leandro.k...@gmail.com> wrote:
No, because _.observation type is Rep[Option[String]] and not Option[String].
I know that. There are extension methods though.
Are you importing driver.simple._ or driver.api._ ?
And that is precisely the point: why there is no implicit conversion from Option[String] to Rep[Option[String]] as is the case in any other types.
You mean the reverse?
--
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/6f649873-36be-440b-8a32-4b2dca2a9d2a%40googlegroups.com.
import slick.driver.H2Driver.api._
class X(tag: Tag) extends Table[(Int, Option[String])](tag, "X") {
def id = column[Int]("id", O.PrimaryKey)
def name = column[Option[String]]("name")
def * = (id, name)
}
val x = TableQuery[X]
def getAllXWithNameNone = {
db.run(x.filter(_.name === None).result)
}
def getAllXWithNameNone = {
db.run(x.filter( _.name.column.isEmpty).result)
}
This is my importimport slick.driver.H2Driver.api._
The same error happens with code below:class X(tag: Tag) extends Table[(Int, Option[String])](tag, "X") {
def id = column[Int]("id", O.PrimaryKey)
def name = column[Option[String]]("name")
def * = (id, name)
}
val x = TableQuery[X]def getAllXWithNameNone = {
db.run(x.filter(_.name === None).result)
}
Compiler error message is:
ambiguous implicit values: both value BooleanColumnCanBeQueryCondition in object CanBeQueryCondition of type => slick.lifted.CanBeQueryCondition[slick.lifted.Rep[Boolean]] and value BooleanOptionColumnCanBeQueryCondition in object CanBeQueryCondition of type => slick.lifted.CanBeQueryCondition[slick.lifted.Rep[Option[Boolean]]] match expected type slick.lifted.CanBeQueryCondition[Nothing]
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/7a14cab8-b6d4-41e7-89a4-1e59fd218c59%40googlegroups.com.
Solved! (but I'm not sure it's the recommended way)def getAllXWithNameNone = {
db.run(x.filter( _.name.column.isEmpty).result)
}
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/bb24e159-7ff4-4f88-830a-006003e9a941%40googlegroups.com.
On Fri, May 29, 2015 at 2:55 AM Leandro Komosinski <leandro.k...@gmail.com> wrote:This is my importimport slick.driver.H2Driver.api._You should get access to all these extension methods: https://github.com/slick/slick/blob/883435050da236e2c3229ee11489dd0e28911d3b/slick/src/main/scala/slick/lifted/ExtensionMethods.scala#L174-L224 via https://github.com/slick/slick/blob/883435050da236e2c3229ee11489dd0e28911d3b/slick/src/main/scala/slick/lifted/ExtensionMethods.scala#L237And I think api should extend ExtensionMethodConversions. Out of curiosity what happens if you write t => anyOptionColumnExtensionMethods(t.column).isEmpty? Does it not find the definition of anyOptionColumnExtensionMethods, or is there some type error somehow?