diff --git a/modules/core/shared/src/main/scala/codec/UuidCodec.scala b/modules/core/shared/src/main/scala/codec/UuidCodec.scala index 780d1dd5..5c517a78 100644 --- a/modules/core/shared/src/main/scala/codec/UuidCodec.scala +++ b/modules/core/shared/src/main/scala/codec/UuidCodec.scala @@ -8,16 +8,20 @@ package codec import cats.syntax.all._ import java.util.UUID import skunk.data.Type +import skunk.data.Arr trait UuidCodec { 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, codec.uuid.parse, Type.uuid) + def _uuid: Codec[Arr[UUID]] = codec.uuid._uuidImpl } -object uuid extends UuidCodec \ No newline at end of file +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) +} diff --git a/modules/tests/shared/src/test/scala/codec/UuidCodecTest.scala b/modules/tests/shared/src/test/scala/codec/UuidCodecTest.scala index 9da0106c..62ea6278 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) }