Last active
April 18, 2023 20:37
-
-
Save daharon/97e8b167911723054ac3845fc35c0b11 to your computer and use it in GitHub Desktop.
Quill fails to use the custom encoding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Generated query: SELECT | |
x1.id, | |
x1.item | |
FROM | |
produce_table x1 | |
WHERE | |
x1.item = APPLE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
libraryDependencies ++= Seq( | |
"dev.zio" %% "zio" % "2.0.10", | |
"org.postgresql" % "postgresql" % "42.5.4", | |
"io.getquill" %% "quill-jdbc-zio" % "4.6.0", | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Generated query: SELECT | |
x1.id, | |
x1.item | |
FROM | |
produce_table x1 | |
WHERE | |
x1.item = 'TEST' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example | |
import java.util.UUID | |
import io.getquill.jdbczio.Quill | |
import io.getquill.{PostgresZioJdbcContext, SnakeCase} | |
import zio.ZIOAppDefault | |
object MappedEncodingTest extends ZIOAppDefault { | |
object Produce extends Enumeration { | |
type Produce = Value | |
val APPLE, PLACEHOLDER = Value | |
} | |
object Ctx extends PostgresZioJdbcContext(SnakeCase) { | |
implicit val encoderProduce: MappedEncoding[Produce.Produce, String] = | |
MappedEncoding(_ => "TEST") | |
implicit val decoderProduce: MappedEncoding[String, Produce.Produce] = | |
MappedEncoding(_ => Produce.PLACEHOLDER) | |
// implicit val encoderProduce: Encoder[Produce.Produce] = encoder( | |
// java.sql.Types.VARCHAR, | |
// (index, value, row) => row.setObject(index, "TEST", java.sql.Types.VARCHAR) | |
// ) | |
// implicit val decoderProduce: Decoder[Produce.Produce] = | |
// decoder((index, row, session) => Produce.PLACEHOLDER) | |
} | |
case class ProduceTable(id: UUID, item: Produce.Produce) | |
val app = { | |
import Ctx.* | |
val query = Ctx.quote { | |
Ctx.query[ProduceTable].filter(_.item == lift(Produce.APPLE)) | |
} | |
for { | |
queryStr <- Ctx.translate(query, true) | |
_ <- zio.Console.printLine(s"Generated query: $queryStr") | |
} yield () | |
} | |
override def run = | |
app | |
.provide( | |
Quill.DataSource.fromPrefix("database"), | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment