Skip to content

Instantly share code, notes, and snippets.

@daharon
Last active April 18, 2023 20:37
Show Gist options
  • Save daharon/97e8b167911723054ac3845fc35c0b11 to your computer and use it in GitHub Desktop.
Save daharon/97e8b167911723054ac3845fc35c0b11 to your computer and use it in GitHub Desktop.
Quill fails to use the custom encoding.
Generated query: SELECT
x1.id,
x1.item
FROM
produce_table x1
WHERE
x1.item = APPLE
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % "2.0.10",
"org.postgresql" % "postgresql" % "42.5.4",
"io.getquill" %% "quill-jdbc-zio" % "4.6.0",
)
Generated query: SELECT
x1.id,
x1.item
FROM
produce_table x1
WHERE
x1.item = 'TEST'
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