New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide comparison operators for supported data types #677
Comments
@mxl sounds good |
@mxl What if we could introduce some new dsl, something like this trait ComparisonOperatorsDsl {
this: Context[_, _] =>
trait ComparisonOperators[T] {
def left: T
def >(right: T) = quote(infix"$left > $right".as[Boolean])
...
}
implicit class StringComparison(left: String) extends ComparisonOperators[String]
}
trait SqlComparisonOperators {
this: SqlContext[_, _] =>
implicit class DateComparison(left: Date) extends ComparisonOperators[Date]
implicit class ContextSpecificComparison(left: ContextSpecific) extends ComparisonOperators[ContextSpecific]
} |
@mentegy Cool! 👍 |
Also it would be nice to provide other operators, for example, string concatenation: implicit class StringConcatenation(left: String) {
def +(right: String) = quote(infix"CONCAT($left, $right)".as[String])
} I suggest to change title and description of this issue and not create another one. |
@mxl for string concat we can just enhance this class https://github.com/getquill/quill/blob/master/quill-sql/src/main/scala/io/getquill/context/sql/dsl/SqlDsl.scala#L8-L10, since it only applicable for sql. But this issue leave only for comparisons |
also i'm not sure that |
@mentegy Ok! |
For things like Date comparison, I'd like to have operators that I can use both inside-of and outside-of Quill contexts. Otherwise my coworkers are going to try to use these wonderful implicit class DateOps(d:java.util.Date /* Or LocalDateTime etc...*/ ) {
def >(o:java.util.Date /* Or LocalDateTime etc...*/):Boolean = d.getTime > o.getTime
def <(o:java.util.Date /* Or LocalDateTime etc...*/):Boolean = d.getTime < o.getTime
// etc...
} Then have val dateContextParser: Parser[Ast] = Parser[Ast] {
case q"$pack.DateOps($d).>($o) =>
BinaryOperation(astParser(d), NumericOperator.`>`, astParser(o))
// etc...
} Then people can use these operators both inside and outside of Quill contexts: // It works here:
val q = quote {
query[Record].filter(_.createdAt > lift(runtimeDateValue))
}
// It also works here:
val r:Record = ...
if (r.createdAt > runtimeDateValue) doSomething() |
Hi, Any updates on this feature? I am looking for a way to compare String using quill. I tried to extend quill using infix function as shown below (code from #862 ), but the operators are conflicting with the default Scala comparison operators.
If I change |
Version:
1.0.2-SNAPSHOT
E. g. for
java.util.Date
:Also:
@getquill/maintainers WDYT?
The text was updated successfully, but these errors were encountered: