zio / zio-protoquill

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

Single parameter case class returns a "Questionable row-class found." compiler warning. #360

Closed KeithGrant closed 9 months ago

KeithGrant commented 11 months ago

Version: 4.7.0 Module: quill-jdbc-zio Database: MirrorSqlDialect)

Expected behavior

[info]    |    ctx.run(joes)
[info]    |    ^^^^^^^^^^^^^
[info]    |Quill Query (compiled in 3ms): SELECT p.first_name AS firstName, p.last_name AS lastName, p.age FROM person p WHERE p.first_name = 'Joe'

Actual behavior

[warn]    |    ctx.run(areas).string
[warn]    |            ^^^^^
[warn]    |Questionable row-class found.
[warn]    |The field 'radius' in the object Circle will be used in the query instead of the field .
[warn]    |Are you sure this is the intended behavior? Perhaps you meant to write an encoder/decoder for Circle?
[warn]    |See the section on Mapped Encodings in the quill documentation here: https://getquill.io/#extending-quill-custom-encoding for the simplest way to do that.

Steps to reproduce the behavior

  def example =   
    val ctx = new SqlMirrorContext(MirrorSqlDialect, Literal)
    import ctx.*
    case class Circle(radius: Float)
    inline def pi = quote{3.14159} 
    inline def areas = quote {
      query[Circle].map(c => pi * c.radius * c.radius)
    }
    ctx.run(areas).string

Workaround

add a second parameter to the case class

  def example =   
    val ctx = new SqlMirrorContext(MirrorSqlDialect, Literal)
    import ctx.*
    case class Circle(radius: Float, dummy: Int)
    inline def pi = quote{3.14159} 
    inline def areas = quote {
      query[Circle].map(c => pi * c.radius * c.radius)
    }
    ctx.run(areas).string

@getquill/maintainers

timzaak commented 9 months ago
 inline def pi = quote(3.1415)

    val area = quote {
      (c: Circle) => {
        val r2 = c.radius * c.radius
        pi * r2
      }
    }

    val areas = quote {
      query[Circle].map(c => area(c))
    }

Doc is here: https://zio.dev/zio-quill/writing-queries#introduction

KeithGrant commented 9 months ago

Yep, that's where I got the example. Looks like 4.8 fixed it. Thanks!