Scala ORM to query SQL databases from Scala via concise, type-safe, and familiar case classes and collection operations. Connects to Postgres, MySql, H2, and Sqlite out of the box
It seems like maxBy has an issue. Unlike minBy, it requires a Numeric[T] constraint, which is inconsistent and unnecessary.
package scalasql.operations
class AggOps[T](v: Aggregatable[T])(...){
def minBy[V: TypeMapper] ...
//it seams that none of those functions need Numeric!
def maxBy[V: Numeric: TypeMapper] ...
def minByOpt[V: Numeric: TypeMapper] ...
def maxByOpt[V: Numeric: TypeMapper] ...
}
Minified example that shows compilation error:
//> using dep com.lihaoyi::scalasql:0.1.11
import scalasql._, SqliteDialect._
import java.time.Instant
// Define your table model classes
//> using dep com.lihaoyi::scalasql:0.1.11
case class City[T[_]](
id: T[Int],
name: T[String],
createdAt: T[Instant],
)
object City extends Table[City]
//uncomment to fix compilation
implicit val ops:Numeric[Instant] = null
def getCities() = City.select
.maxBy(_.createdAt) //<---- [error] implicit Ordering defined for java.time.Instant.
Not sure why we get Ordering issue:
[error] No implicit Ordering defined for java.time.Instant.
[error] .maxBy(_.createdAt)
It seems like
maxBy
has an issue. UnlikeminBy
, it requires aNumeric[T]
constraint, which is inconsistent and unnecessary.Minified example that shows compilation error:
Not sure why we get Ordering issue:
Discord question that exposed it: https://discord.com/channels/632150470000902164/940067748103487558/1309464062014525451
Complete code that runs queries