Skip to content

Commit 706dc37

Browse files
authored
Merge pull request #1324 from nigredo-tori/1310-uuid-array
Add _uuid (UUID array) codec
2 parents e5d72ee + 0a8c22b commit 706dc37

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

modules/core/shared/src/main/scala/codec/UuidCodec.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ package codec
88
import cats.syntax.all._
99
import java.util.UUID
1010
import skunk.data.Type
11+
import skunk.data.Arr
1112

1213
trait UuidCodec {
1314

1415
val uuid: Codec[UUID] =
15-
Codec.simple[UUID](
16-
u => u.toString,
17-
s => Either.catchOnly[IllegalArgumentException](UUID.fromString(s)).leftMap(_.getMessage),
18-
Type.uuid
19-
)
16+
Codec.simple[UUID](_.toString, codec.uuid.parse, Type.uuid)
2017

18+
def _uuid: Codec[Arr[UUID]] = codec.uuid._uuidImpl
2119
}
2220

23-
object uuid extends UuidCodec
21+
object uuid extends UuidCodec {
22+
private[codec] def parse(s: String): Either[String, UUID] =
23+
Either.catchOnly[IllegalArgumentException](UUID.fromString(s)).leftMap(_.getMessage)
24+
25+
private[codec] val _uuidImpl: Codec[Arr[UUID]] =
26+
Codec.array[UUID](_.toString, parse, Type._uuid)
27+
}

modules/tests/shared/src/test/scala/codec/UuidCodecTest.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package tests
66
package codec
77
import skunk.codec.all._
8+
import skunk.data.Arr
89
import java.util.UUID
910

1011
/** Test that we can round=trip values via codecs. */
@@ -17,6 +18,8 @@ class UuidCodecTest extends CodecTest {
1718
roundtripTest(uuid.opt)(Some(u1), Some(u2), None)
1819
decodeFailureTest(time, List("x"))
1920

21+
val Some(arr) = Arr(u1, u2).reshape(2,1): @unchecked
22+
roundtripTest(_uuid)(Arr.empty, arr)
2023
}
2124

2225

0 commit comments

Comments
 (0)