zio-quill icon indicating copy to clipboard operation
zio-quill copied to clipboard

Type Error : MappedEncoding[X, JsonValue[X]] with None

Open mazers0129 opened this issue 1 year ago • 0 comments

This template isn't a strict requirement to open issues, but please try to provide as much information as possible.

Version: 4.6.0 Module: quill-jdbc-zio Database: postgresql

case class TestData(first: String)
case class Test(id: String, data: Option[TestData])
implicit val encoder: JsonEncoder[TestData] = DeriveJsonEncoder.gen
implicit val dbEncoder: MappedEncoding[TestData, JsonValue[TestData]] = MappedEncoding(JsonValue(_))

throw exception : org.postgresql.util.PSQLException: ERROR: column "data" is of type json but expression is of type character varying with this code

ctx.run(query[Test].insertValue(lift(Test("test", None)))).provideEnvironment(layer)

work fine with this code

ctx.run(query[Test].insertValue(lift(Test("test", Some(TestData("1")))))).provideEnvironment(layer)

work fine if use

implicit val dbOptionEncoder: MappedEncoding[Option[TestData], JsonValue[Option[TestData]]] = MappedEncoding(JsonValue(_))

instead of

implicit val dbEncoder: MappedEncoding[TestData, JsonValue[TestData]] = MappedEncoding(JsonValue(_))

but if use both code throw exception

mazers0129 avatar Oct 28 '22 07:10 mazers0129