Skip to content

Commit

Permalink
Merge pull request #32 from narma/request_exactly_one_item_in_selectF…
Browse files Browse the repository at this point in the history
…irst

change default limit to 1 in selectFirst
  • Loading branch information
myazinn authored Dec 31, 2022
2 parents 77dcbe4 + 916142c commit fc03e65
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/scala/zio/cassandra/session/Session.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import zio.stream.{ Stream, ZStream }

import scala.jdk.CollectionConverters.IterableHasAsScala
import scala.jdk.OptionConverters.RichOptional
import scala.language.existentials

trait Session {

Expand Down Expand Up @@ -106,8 +107,11 @@ object Session {
override def select(stmt: Statement[_]): Stream[Throwable, Row] =
repeatZIO(ZIO.succeed(stmt), continuous = false)

override def selectFirst(stmt: Statement[_]): Task[Option[Row]] =
execute(stmt).map(rs => Option(rs.one()))
override def selectFirst(stmt: Statement[_]): Task[Option[Row]] = {
// setPageSize returns T <: Statement[T] for any T, but Scala can't figure it out without clues that will spoil library API
val single = stmt.setPageSize(1).asInstanceOf[Statement[_]]
execute(single).map(rs => Option(rs.one()))
}

override def metrics: Option[Metrics] =
underlying.getMetrics.toScala
Expand Down

0 comments on commit fc03e65

Please sign in to comment.