I am trying to run a query like .filter(_.id === 1).firstOption
but the compiler complains there is no symbol firstOption
. Was this removed in slick 3? What can I use instead?
To limit the number of results before calling result, use take(num)
. For example like this:
val result: Future[Option[Whatever]] = db.run((query.filter(_.id === 1).take(1)).result).map(_.headOption)
According to the official docs, the above statement boils down using headOption
on the result method.
val result: Future[Option[Whatever]] = db.run((query.filter(_.id === 1)).result.headOption)
query.result
returns an object of type DBIOAction
. An action in slick is something that can be executed on a database. The actual execution is done by passing the action to db.run()
or db.stream()
. You can find a more detailed explanation here: http://slick.typesafe.com/doc/3.0.0/api/index.html#slick.dbio.DBIOAction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With