Open frekw opened 1 year ago
/bounty $50
/attempt #83
with your implementation plan/claim #83
in the PR body to claim the bountyThank you for contributing to zio/zio-jdbc!
Add a bounty • Share on socials
Attempt | Started (GMT+0) | Solution |
---|---|---|
🟢 @andrzejressel | #131 |
Something like that in scope works fine:
test("Custom JdbcEncoder") {
implicit val byteArrayjdbcEncoder: JdbcEncoder[Array[Byte]] =
value => s"FROM_BASE64('${Base64.getEncoder.encodeToString(value)}')"
implicit def segmentFromJdbcEncoder[A](obj: A)(implicit encoder: JdbcEncoder[A]): Segment =
Nested(encoder.encode(obj))
val bytes = Array[Byte](1, 2, 3)
val result = sql"UPDATE foo SET bytes = $bytes"
assertTrue(
result.toString == "Sql(UPDATE foo SET bytes = FROM_BASE64('AQID'))"
)
}
But having it in library itself causes a lot of errors due to implicit conversion ambiguity.
We can solve the implicit conversion ambiguity with implicit prioritization tricks (or something else...).
💡 @andrzejressel submitted a pull request that claims the bounty. You can visit your org dashboard to reward.
Hi!
I'm playing around with zio-jdbc together with Spanner, which natively supports raw bytes as a datatype.
I've declared a
JdbcEncoder
as follows:and that works greats togehter with
.values
. However, when I execute an update statement, e.gUPDATE foo SET bytes = $bytes WHERE id = $id
myJdbcEncoder
isn't being used, and I have to reimplement the same encoding as I do for inserts (likely because zio-jdbc doesn't check for the typeclass here). It would be really nice if zio-jdbc leverage the sameJdbcEncoder
I've already specified!