-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Branch 0.8 (#16)
* refactor: split PredOp into PredicateBinary and PredicateUnary * fit: collection values * refactor: delete Syms * fit: between and not between demo * review fixes * review fixes --------- Co-authored-by: m.karavashkin <[email protected]>
Showing
22 changed files
with
465 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 0 additions & 103 deletions
103
core/src/main/scala/io/github/rafafrdz/criteria4s/core/PredOp.scala
This file was deleted.
Oops, something went wrong.
168 changes: 168 additions & 0 deletions
168
core/src/main/scala/io/github/rafafrdz/criteria4s/core/Predicate.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package io.github.rafafrdz.criteria4s.core | ||
|
||
import io.github.rafafrdz.criteria4s.core.Criteria._ | ||
import io.github.rafafrdz.criteria4s.instances.builder.{Builder1, Builder2} | ||
|
||
sealed trait Predicate[T <: CriteriaTag] | ||
|
||
trait PredicateUnary[T <: CriteriaTag] extends Predicate[T] { | ||
def eval[V](ref: Ref[T, V])(implicit show: Show[V, T]): Criteria[T] | ||
} | ||
|
||
trait PredicateBinary[T <: CriteriaTag] extends Predicate[T] { | ||
def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] | ||
} | ||
|
||
object PredicateUnary { | ||
trait ISNULL[T <: CriteriaTag] extends PredicateUnary[T] | ||
|
||
trait ISNOTNULL[T <: CriteriaTag] extends PredicateUnary[T] | ||
|
||
implicit val isNullBuilder: Builder1[ISNULL] = new Builder1[ISNULL] { | ||
override def build[T <: CriteriaTag](F: String => String): ISNULL[T] = new ISNULL[T] { | ||
override def eval[V](ref: Ref[T, V])(implicit show: Show[V, T]): Criteria[T] = pure( | ||
F(ref.asString) | ||
) | ||
} | ||
} | ||
|
||
implicit val isNotNullBuilder: Builder1[ISNOTNULL] = new Builder1[ISNOTNULL] { | ||
override def build[T <: CriteriaTag](F: String => String): ISNOTNULL[T] = new ISNOTNULL[T] { | ||
override def eval[V](ref: Ref[T, V])(implicit show: Show[V, T]): Criteria[T] = pure( | ||
F(ref.asString) | ||
) | ||
} | ||
} | ||
} | ||
|
||
object PredicateBinary { | ||
|
||
trait GT[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
trait LT[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
trait EQ[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
trait NEQ[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
trait GEQ[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
trait LEQ[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
trait LIKE[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
trait IN[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
trait NOTIN[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
trait BETWEEN[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
trait NOTBETWEEN[T <: CriteriaTag] extends PredicateBinary[T] | ||
|
||
implicit val gtBuilder: Builder2[GT] = new Builder2[GT] { | ||
override def build[T <: CriteriaTag]( | ||
F: (String, String) => String | ||
): GT[T] = new GT[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
|
||
implicit val ltBuilder: Builder2[LT] = new Builder2[LT] { | ||
override def build[T <: CriteriaTag](F: (String, String) => String): LT[T] = new LT[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
|
||
implicit val eqBuilder: Builder2[EQ] = new Builder2[EQ] { | ||
override def build[T <: CriteriaTag](F: (String, String) => String): EQ[T] = new EQ[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
|
||
implicit val neqBuilder: Builder2[NEQ] = new Builder2[NEQ] { | ||
override def build[T <: CriteriaTag](F: (String, String) => String): NEQ[T] = new NEQ[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
|
||
implicit val geqBuilder: Builder2[GEQ] = new Builder2[GEQ] { | ||
override def build[T <: CriteriaTag](F: (String, String) => String): GEQ[T] = new GEQ[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
|
||
implicit val leqBuilder: Builder2[LEQ] = new Builder2[LEQ] { | ||
override def build[T <: CriteriaTag](F: (String, String) => String): LEQ[T] = new LEQ[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
|
||
implicit val likeBuilder: Builder2[LIKE] = new Builder2[LIKE] { | ||
override def build[T <: CriteriaTag](F: (String, String) => String): LIKE[T] = new LIKE[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
|
||
implicit val inBuilder: Builder2[IN] = new Builder2[IN] { | ||
override def build[T <: CriteriaTag](F: (String, String) => String): IN[T] = new IN[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
|
||
implicit val notinBuilder: Builder2[NOTIN] = new Builder2[NOTIN] { | ||
override def build[T <: CriteriaTag](F: (String, String) => String): NOTIN[T] = | ||
new NOTIN[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
|
||
implicit val betweenBuilder: Builder2[BETWEEN] = new Builder2[BETWEEN] { | ||
override def build[T <: CriteriaTag](F: (String, String) => String): BETWEEN[T] = | ||
new BETWEEN[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
|
||
implicit val notbetweenBuilder: Builder2[NOTBETWEEN] = new Builder2[NOTBETWEEN] { | ||
override def build[T <: CriteriaTag](F: (String, String) => String): NOTBETWEEN[T] = | ||
new NOTBETWEEN[T] { | ||
override def eval[L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = pure(F(cr1.asString, cr2.asString)) | ||
} | ||
} | ||
} |
51 changes: 23 additions & 28 deletions
51
core/src/main/scala/io/github/rafafrdz/criteria4s/core/Ref.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,38 @@ | ||
package io.github.rafafrdz.criteria4s.core | ||
|
||
sealed trait Ref[D <: CriteriaTag] { | ||
def ref: Criteria[D] | ||
|
||
override def toString: String = ref.value | ||
sealed trait Ref[D <: CriteriaTag, V] { | ||
def asString(implicit show: Show[V, D]): String | ||
} | ||
|
||
object Ref { | ||
|
||
trait Value[+V, D <: CriteriaTag] extends Ref[D] | ||
|
||
trait Collection[V, D <: CriteriaTag] extends Value[Seq[V], D] | ||
|
||
trait Col[D <: CriteriaTag] extends Ref[D] | ||
|
||
trait Bool[D <: CriteriaTag] extends Value[Boolean, D] with Criteria[D] { | ||
self => | ||
|
||
override def value: String = ref.value | ||
trait Value[D <: CriteriaTag, V] extends Ref[D, V] | ||
trait Collection[D <: CriteriaTag, V] extends Ref[D, Seq[V]] | ||
trait Col[D <: CriteriaTag] extends Ref[D, Column] | ||
trait Bool[D <: CriteriaTag] extends Value[D, Boolean] with Criteria[D] | ||
trait Range[D <: CriteriaTag, V] extends Ref[D, (V, V)] | ||
|
||
override def toString: String = value | ||
} | ||
private[criteria4s] def nothing[T <: CriteriaTag]: Value[T, Nothing] = | ||
(_: Show[Nothing, T]) => "" | ||
|
||
private[criteria4s] def nothing[T <: CriteriaTag]: Value[Nothing, T] = | ||
new Value[Nothing, T] { | ||
override def ref: Criteria[T] = Criteria.pure("") | ||
} | ||
private[criteria4s] def value[V, D <: CriteriaTag](v: V): Value[V, D] = | ||
new Value[V, D] { | ||
override def ref: Criteria[D] = Criteria.pure(v.toString) | ||
} | ||
private[criteria4s] def value[V, D <: CriteriaTag](v: V): Value[D, V] = | ||
(show: Show[V, D]) => show.show(v) | ||
|
||
private[criteria4s] def col[D <: CriteriaTag](v: String): Col[D] = new Col[D] { | ||
override def ref: Criteria[D] = Criteria.pure(v) | ||
} | ||
private[criteria4s] def col[D <: CriteriaTag](v: Column): Col[D] = | ||
(show: Show[Column, D]) => show.show(v) | ||
|
||
private[criteria4s] def bool[D <: CriteriaTag](v: Boolean): Bool[D] = | ||
new Bool[D] { | ||
override def ref: Criteria[D] = Criteria.pure(v.toString) | ||
override def value: String = v.toString | ||
override def asString(implicit show: Show[Boolean, D]): String = v.toString | ||
} | ||
|
||
private[criteria4s] def array[V, D <: CriteriaTag](vs: V*): Collection[D, V] = | ||
(show: Show[Seq[V], D]) => show.show(vs) | ||
|
||
private[criteria4s] def range[V, D <: CriteriaTag](left: V, right: V): Range[D, V] = | ||
(show: Show[(V, V), D]) => show.show((left, right)) | ||
|
||
} | ||
|
||
case class Column(colName: String) extends AnyVal |
12 changes: 12 additions & 0 deletions
12
core/src/main/scala/io/github/rafafrdz/criteria4s/core/Show.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.rafafrdz.criteria4s.core | ||
|
||
trait Show[-V, D <: CriteriaTag] { | ||
def show(v: V): String | ||
} | ||
|
||
object Show { | ||
def create[V, D <: CriteriaTag](f: V => String): Show[V, D] = (v: V) => f(v) | ||
|
||
implicit def defaultStringShow[D <: CriteriaTag]: Show[String, D] = identity | ||
implicit def defaultIntShow[V <: AnyVal, D <: CriteriaTag]: Show[V, D] = create(_.toString) | ||
} |
25 changes: 0 additions & 25 deletions
25
core/src/main/scala/io/github/rafafrdz/criteria4s/core/Sym.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 52 additions & 27 deletions
79
core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/predicates.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 85 additions & 46 deletions
131
core/src/main/scala/io/github/rafafrdz/criteria4s/functions/predicates.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,112 @@ | ||
package io.github.rafafrdz.criteria4s.functions | ||
|
||
import io.github.rafafrdz.criteria4s.core.Criteria.CriteriaTag | ||
import io.github.rafafrdz.criteria4s.core.PredOp._ | ||
import io.github.rafafrdz.criteria4s.core.Ref.{Bool, Col, Value} | ||
import io.github.rafafrdz.criteria4s.core.{Criteria, Ref, Sym} | ||
import io.github.rafafrdz.criteria4s.core.PredicateBinary._ | ||
import io.github.rafafrdz.criteria4s.core.PredicateUnary._ | ||
import io.github.rafafrdz.criteria4s.core.Ref.{Bool, Col, Collection, Value} | ||
import io.github.rafafrdz.criteria4s.core.{Column, Criteria, Ref, Show} | ||
|
||
private[functions] trait predicates { | ||
|
||
def lit[T <: CriteriaTag: Sym, V](v: V): Value[V, T] = | ||
implicitly[Sym[T]].value[V](Ref.value(v)) | ||
def lit[T <: CriteriaTag, V](v: V): Value[T, V] = | ||
Ref.value(v) | ||
|
||
def bool[T <: CriteriaTag: Sym](v: Boolean): Bool[T] = | ||
implicitly[Sym[T]].bool(Ref.bool(v)) | ||
def bool[T <: CriteriaTag](v: Boolean): Bool[T] = | ||
Ref.bool(v) | ||
|
||
private[criteria4s] def __[T <: CriteriaTag]: Value[Nothing, T] = Ref.nothing[T] | ||
private[criteria4s] def __[T <: CriteriaTag]: Value[T, Nothing] = Ref.nothing[T] | ||
|
||
def col[T <: CriteriaTag: Sym](ref: String): Col[T] = implicitly[Sym[T]].col(Ref.col(ref)) | ||
def col[T <: CriteriaTag](ref: String): Col[T] = Ref.col(Column(ref)) | ||
|
||
// private def array_[T <: CriteriaTag: ARRAY](values: Criteria[T]*): Criteria[T] = pred[T, ARRAY[T]](values: _*) | ||
// | ||
// def array[T <: CriteriaTag: ARRAY, V](values: V*): Criteria[T] = array_(values.map(lit[T, V]): _*) | ||
// | ||
def lt[T <: CriteriaTag: LT](cr1: Ref[T], cr2: Ref[T]): Criteria[T] = | ||
pred[T, LT[T]](cr1, cr2) | ||
def array[T <: CriteriaTag, V](vs: V*): Collection[T, V] = Ref.array(vs: _*) | ||
|
||
def gt[T <: CriteriaTag: GT](cr1: Ref[T], cr2: Ref[T]): Criteria[T] = | ||
pred[T, GT[T]](cr1, cr2) | ||
def range[T <: CriteriaTag, V](left: V, right: V): Ref.Range[T, V] = Ref.range(left, right) | ||
|
||
def ===[T <: CriteriaTag: EQ](cr1: Ref[T], cr2: Ref[T]): Criteria[T] = | ||
pred[T, EQ[T]](cr1, cr2) | ||
|
||
def =!=[T <: CriteriaTag: NEQ](cr1: Ref[T], cr2: Ref[T]): Criteria[T] = | ||
pred[T, NEQ[T]](cr1, cr2) | ||
def lt[T <: CriteriaTag: LT, L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
predBinary[T, LT[T], L, R](cr1, cr2) | ||
|
||
def neq[T <: CriteriaTag: NEQ](cr1: Ref[T], cr2: Ref[T]): Criteria[T] = | ||
pred[T, NEQ[T]](cr1, cr2) | ||
def gt[T <: CriteriaTag: GT, L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
predBinary[T, GT[T], L, R](cr1, cr2) | ||
|
||
def geq[T <: CriteriaTag: GEQ](cr1: Ref[T], cr2: Ref[T]): Criteria[T] = | ||
pred[T, GEQ[T]](cr1, cr2) | ||
def ===[T <: CriteriaTag: EQ, L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
predBinary[T, EQ[T], L, R](cr1, cr2) | ||
|
||
def leq[T <: CriteriaTag: LEQ](cr1: Ref[T], cr2: Ref[T]): Criteria[T] = | ||
pred[T, LEQ[T]](cr1, cr2) | ||
def =!=[T <: CriteriaTag: NEQ, L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
predBinary[T, NEQ[T], L, R](cr1, cr2) | ||
|
||
def like[T <: CriteriaTag: LIKE](cr1: Ref[T], cr2: Ref[T]): Criteria[T] = | ||
pred[T, LIKE[T]](cr1, cr2) | ||
def neq[T <: CriteriaTag: NEQ, L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
predBinary[T, NEQ[T], L, R](cr1, cr2) | ||
|
||
def in[T <: CriteriaTag: IN](cr1: Ref[T], cr2: Ref[T]): Criteria[T] = | ||
pred[T, IN[T]](cr1, cr2) | ||
def geq[T <: CriteriaTag: GEQ, L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
predBinary[T, GEQ[T], L, R](cr1, cr2) | ||
|
||
def notin[T <: CriteriaTag: NOTIN](cr1: Ref[T], cr2: Ref[T]): Criteria[T] = | ||
pred[T, NOTIN[T]](cr1, cr2) | ||
def leq[T <: CriteriaTag: LEQ, L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
predBinary[T, LEQ[T], L, R](cr1, cr2) | ||
|
||
def isNull[T <: CriteriaTag: ISNULL](cr1: Ref[T]): Criteria[T] = | ||
pred[T, ISNULL[T]](cr1, __) | ||
def like[T <: CriteriaTag: LIKE, L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
predBinary[T, LIKE[T], L, R](cr1, cr2) | ||
|
||
def isNotNull[T <: CriteriaTag: ISNOTNULL](cr1: Ref[T]): Criteria[T] = | ||
pred[T, ISNOTNULL[T]](cr1, __) | ||
def in[T <: CriteriaTag: IN, L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
predBinary[T, IN[T], L, R](cr1, cr2) | ||
|
||
def between[T <: CriteriaTag: BETWEEN]( | ||
cr1: Ref[T], | ||
cr2: Ref[T] | ||
def notIn[T <: CriteriaTag: NOTIN, L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
pred[T, BETWEEN[T]](cr1, cr2) | ||
predBinary[T, NOTIN[T], L, R](cr1, cr2) | ||
|
||
def notBetween[T <: CriteriaTag: NOTBETWEEN]( | ||
cr1: Ref[T], | ||
cr2: Ref[T] | ||
def isNull[T <: CriteriaTag: ISNULL, V](cr1: Ref[T, V])(implicit show: Show[V, T]): Criteria[T] = | ||
predUnary[T, ISNULL[T], V](cr1) | ||
|
||
def isNotNull[T <: CriteriaTag: ISNOTNULL, V](cr1: Ref[T, V])(implicit | ||
show: Show[V, T] | ||
): Criteria[T] = | ||
predUnary[T, ISNOTNULL[T], V](cr1) | ||
|
||
def between[T <: CriteriaTag: BETWEEN, L, R]( | ||
cr1: Ref[T, L], | ||
cr2: Ref[T, R] | ||
)(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
predBinary[T, BETWEEN[T], L, R](cr1, cr2) | ||
|
||
def notBetween[T <: CriteriaTag: NOTBETWEEN, L, R]( | ||
cr1: Ref[T, L], | ||
cr2: Ref[T, R] | ||
)(implicit | ||
showL: Show[L, T], | ||
showR: Show[R, T] | ||
): Criteria[T] = | ||
pred[T, NOTBETWEEN[T]](cr1, cr2) | ||
predBinary[T, NOTBETWEEN[T], L, R](cr1, cr2) | ||
} | ||
|
||
object predicates extends predicates |
7 changes: 0 additions & 7 deletions
7
core/src/main/scala/io/github/rafafrdz/criteria4s/instances/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/ArraysExample.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.rafafrdz.criteria4s.examples | ||
|
||
import io.github.rafafrdz.criteria4s.core._ | ||
import io.github.rafafrdz.criteria4s.examples.datastores.{Postgres, WeirdDatastore} | ||
import io.github.rafafrdz.criteria4s.functions._ | ||
|
||
object ArraysExample extends App { | ||
val aIsNull: Criteria[Postgres] = isNull(col("a")) | ||
def aIsNullAlgebra[ | ||
T <: CriteriaTag: ISNULL: Show[Column, *] | ||
]: Criteria[T] = isNull(col("a")) | ||
|
||
val numberInArray: Criteria[Postgres] = in(col("a"), array(1, 2, 3)) | ||
def numberInArrayAlgebra[T <: CriteriaTag: IN: Show[Column, *]: Show[Seq[Int], *]]: Criteria[T] = | ||
in(col("a"), array(1, 2, 3)) | ||
|
||
val combined: Criteria[Postgres] = or(aIsNull, numberInArray) | ||
val moreCombined: Criteria[Postgres] = or(combined, ===(col("b"), lit(10))) | ||
|
||
println(aIsNull) | ||
println(aIsNullAlgebra[Postgres]) | ||
println(aIsNullAlgebra[WeirdDatastore]) | ||
|
||
println(numberInArray) | ||
println(numberInArrayAlgebra[Postgres]) | ||
println(numberInArrayAlgebra[WeirdDatastore]) | ||
|
||
println(combined) | ||
println(moreCombined) | ||
} |
21 changes: 21 additions & 0 deletions
21
examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/BetweenExample.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.github.rafafrdz.criteria4s.examples | ||
|
||
import io.github.rafafrdz.criteria4s.core._ | ||
import io.github.rafafrdz.criteria4s.examples.datastores.{Postgres, WeirdDatastore} | ||
import io.github.rafafrdz.criteria4s.extensions._ | ||
import io.github.rafafrdz.criteria4s.functions._ | ||
|
||
object BetweenExample extends App { | ||
val simpleBetween: Criteria[Postgres] = col[Postgres]("a").between(range(1, 10)) | ||
val simpleNotBetween: Criteria[Postgres] = col[Postgres]("b").notBetween(range("A", "Z")) | ||
|
||
def taglessFinalBetweenExample[ | ||
T <: CriteriaTag: BETWEEN: Show[Column, *]: Show[(Int, Int), *] | ||
]: Criteria[T] = | ||
col[T]("column") between range(100, 150) | ||
|
||
println(simpleBetween) | ||
println(simpleNotBetween) | ||
println(taglessFinalBetweenExample[Postgres]) | ||
println(taglessFinalBetweenExample[WeirdDatastore]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters