From e9f513de590f894511865afe0b14619af187358b Mon Sep 17 00:00:00 2001 From: Dmitry Polienko Date: Sat, 4 Jul 2026 14:43:42 +0700 Subject: [PATCH 1/2] Add _uuid (UUID array) codec --- .../shared/src/main/scala/codec/UuidCodec.scala | 14 ++++++++------ .../src/test/scala/codec/UuidCodecTest.scala | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/core/shared/src/main/scala/codec/UuidCodec.scala b/modules/core/shared/src/main/scala/codec/UuidCodec.scala index 780d1dd5b..80aca0074 100644 --- a/modules/core/shared/src/main/scala/codec/UuidCodec.scala +++ b/modules/core/shared/src/main/scala/codec/UuidCodec.scala @@ -8,16 +8,18 @@ package codec import cats.syntax.all._ import java.util.UUID import skunk.data.Type +import skunk.data.Arr trait UuidCodec { + private def parse(s: String): Either[String, UUID] = + Either.catchOnly[IllegalArgumentException](UUID.fromString(s)).leftMap(_.getMessage) + val uuid: Codec[UUID] = - Codec.simple[UUID]( - u => u.toString, - s => Either.catchOnly[IllegalArgumentException](UUID.fromString(s)).leftMap(_.getMessage), - Type.uuid - ) + Codec.simple[UUID](_.toString, parse, Type.uuid) + val _uuid: Codec[Arr[UUID]] = + Codec.array[UUID](_.toString, parse, Type._uuid) } -object uuid extends UuidCodec \ No newline at end of file +object uuid extends UuidCodec diff --git a/modules/tests/shared/src/test/scala/codec/UuidCodecTest.scala b/modules/tests/shared/src/test/scala/codec/UuidCodecTest.scala index 9da0106ce..62ea62786 100644 --- a/modules/tests/shared/src/test/scala/codec/UuidCodecTest.scala +++ b/modules/tests/shared/src/test/scala/codec/UuidCodecTest.scala @@ -5,6 +5,7 @@ package tests package codec import skunk.codec.all._ +import skunk.data.Arr import java.util.UUID /** Test that we can round=trip values via codecs. */ @@ -17,6 +18,8 @@ class UuidCodecTest extends CodecTest { roundtripTest(uuid.opt)(Some(u1), Some(u2), None) decodeFailureTest(time, List("x")) + val Some(arr) = Arr(u1, u2).reshape(2,1): @unchecked + roundtripTest(_uuid)(Arr.empty, arr) } From c7e9c883272abc891c8b30548860a13ebe131bb2 Mon Sep 17 00:00:00 2001 From: Dmitry Polienko Date: Sun, 5 Jul 2026 13:37:56 +0700 Subject: [PATCH 2/2] Tweak the code to avoid binary incompatibility --- .../shared/src/main/scala/codec/UuidCodec.scala | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/core/shared/src/main/scala/codec/UuidCodec.scala b/modules/core/shared/src/main/scala/codec/UuidCodec.scala index 80aca0074..5c517a785 100644 --- a/modules/core/shared/src/main/scala/codec/UuidCodec.scala +++ b/modules/core/shared/src/main/scala/codec/UuidCodec.scala @@ -12,14 +12,16 @@ import skunk.data.Arr trait UuidCodec { - private def parse(s: String): Either[String, UUID] = - Either.catchOnly[IllegalArgumentException](UUID.fromString(s)).leftMap(_.getMessage) - val uuid: Codec[UUID] = - Codec.simple[UUID](_.toString, parse, Type.uuid) + Codec.simple[UUID](_.toString, codec.uuid.parse, Type.uuid) - val _uuid: Codec[Arr[UUID]] = - Codec.array[UUID](_.toString, parse, Type._uuid) + def _uuid: Codec[Arr[UUID]] = codec.uuid._uuidImpl } -object uuid extends UuidCodec +object uuid extends UuidCodec { + private[codec] def parse(s: String): Either[String, UUID] = + Either.catchOnly[IllegalArgumentException](UUID.fromString(s)).leftMap(_.getMessage) + + private[codec] val _uuidImpl: Codec[Arr[UUID]] = + Codec.array[UUID](_.toString, parse, Type._uuid) +}