From 916142c6a439e80a282991b65a4a9a664a6866d2 Mon Sep 17 00:00:00 2001 From: "nikita.myazin" Date: Fri, 30 Dec 2022 21:39:37 +0200 Subject: [PATCH] change default limit to 1 in selectFirst --- src/main/scala/zio/cassandra/session/Session.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/scala/zio/cassandra/session/Session.scala b/src/main/scala/zio/cassandra/session/Session.scala index ee479c6..37f325d 100644 --- a/src/main/scala/zio/cassandra/session/Session.scala +++ b/src/main/scala/zio/cassandra/session/Session.scala @@ -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 { @@ -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