Skip to content

Commit

Permalink
change default limit to 1 in selectFirst
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita.myazin committed Dec 30, 2022
1 parent 77dcbe4 commit 916142c
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 916142c

Please sign in to comment.