diff --git a/core/shared/src/main/scala/porcupine/db.scala b/core/shared/src/main/scala/porcupine/db.scala index 82b2540..1bab5c1 100644 --- a/core/shared/src/main/scala/porcupine/db.scala +++ b/core/shared/src/main/scala/porcupine/db.scala @@ -110,15 +110,15 @@ private abstract class AbstractStatement[F[_], A, B](using F: MonadCancelThrow[F final def execute(using Unit <:< B)(args: A) = cursor(args).use(_.fetch(1).void) - final def option(args: A) = cursor(args).use(_.fetch(1).flatMap { - case (Nil, false) => F.pure(None) - case (head :: Nil, false) => F.pure(Some(head)) + final def option(args: A) = cursor(args).use(_.fetch(2).flatMap { + case (Nil, _) => F.pure(None) + case (head :: Nil, _) => F.pure(Some(head)) case _ => F.raiseError(new RuntimeException("More than 1 row")) }) - final def unique(args: A) = cursor(args).use(_.fetch(1).flatMap { - case (Nil, false) => F.raiseError(new NoSuchElementException) - case (head :: Nil, false) => F.pure(head) + final def unique(args: A) = cursor(args).use(_.fetch(2).flatMap { + case (Nil, _) => F.raiseError(new NoSuchElementException) + case (head :: Nil, _) => F.pure(head) case _ => F.raiseError(new RuntimeException("More than 1 row")) }) diff --git a/core/shared/src/test/scala/porcupine/PorcupineTest.scala b/core/shared/src/test/scala/porcupine/PorcupineTest.scala index e6ce7cf..5f0e9b3 100644 --- a/core/shared/src/test/scala/porcupine/PorcupineTest.scala +++ b/core/shared/src/test/scala/porcupine/PorcupineTest.scala @@ -31,11 +31,11 @@ object PorcupineTest extends IOApp.Simple: sql"insert into porcupine values(${`null`}, $integer, $real, $text, $blob);".command, (None, 42L, 3.14, "quill-pig", ByteVector(0, 1, 2, 3)), ) *> - db.execute( + db.unique( sql"select b, t, r, i, n from porcupine;" .query(blob *: text *: real *: integer *: `null` *: nil), ).flatMap { - case List((ByteVector(0, 1, 2, 3), "quill-pig", 3.14, 42, None)) => IO.unit + case (ByteVector(0, 1, 2, 3), "quill-pig", 3.14, 42, None) => IO.unit case other => IO.raiseError(new AssertionError(other)) } }