zio / zio-protoquill

Quill for Scala 3
Apache License 2.0
209 stars 48 forks source link

Failed query by sql Date #310

Closed zhiwilliam closed 1 year ago

zhiwilliam commented 1 year ago

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

Version: 4.6.0.1 Module: [quill-zio] Database: postgres

Expected behavior

SQL can be properly generated.

Actual behavior

Cannot Find a 'java.sql.Date' Encoder of Date.valueOf("2023-08-02")

Steps to reproduce the behavior

val ctx = new SqlMirrorContext(PostgresDialect, Literal) import ctx._ import java.sql.Date case class DailySaleB(id: Int, total: BigDecimal, date: Date) import io.getquill.extras.SqlDateOps

inline def q3 = quote { query[DailySaleB].filter(x => x.date < lift(Date.valueOf("2023-08-02")))//.map(_.total).max } run(q3).string

Workaround

@getquill/maintainers

zhiwilliam commented 1 year ago

These code seems work:

val ctx = new SqlMirrorContext(PostgresDialect, Literal) import ctx._

extension (time: Timestamp) inline def toDate: LocalDate = sql"DATE($time)".as[LocalDate]

extension (date: LocalDate) inline def <(compareTo: LocalDate): Boolean = quote { sql"$date < $compareTo".as[Boolean] }

I will close it.