-
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.
Add support for unary NOT conjuction (#32)
close #22
- Loading branch information
Showing
9 changed files
with
163 additions
and
101 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
5 changes: 3 additions & 2 deletions
5
core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/conjunctions.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
14 changes: 12 additions & 2 deletions
14
core/src/main/scala/io/github/rafafrdz/criteria4s/functions/conjunctions.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,15 +1,25 @@ | ||
package io.github.rafafrdz.criteria4s.functions | ||
|
||
import io.github.rafafrdz.criteria4s.core.{Criteria, CriteriaTag} | ||
import io.github.rafafrdz.criteria4s.core.Conjuction._ | ||
import io.github.rafafrdz.criteria4s.core._ | ||
|
||
private[functions] trait conjunctions { | ||
|
||
def and[T <: CriteriaTag: AND](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = | ||
cond[T, AND[T]](cr1, cr2) | ||
|
||
def &&[T <: CriteriaTag: AND](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = | ||
and(cr1, cr2) | ||
|
||
def or[T <: CriteriaTag: OR](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = | ||
cond[T, OR[T]](cr1, cr2) | ||
|
||
def ||[T <: CriteriaTag: OR](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = | ||
or(cr1, cr2) | ||
|
||
def not[T <: CriteriaTag: NOT](cr: Criteria[T]): Criteria[T] = | ||
cond[T, NOT[T]](cr) | ||
|
||
def !![T <: CriteriaTag: NOT](cr: Criteria[T]): Criteria[T] = not(cr) | ||
|
||
} | ||
object conjunctions extends conjunctions |
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
43 changes: 43 additions & 0 deletions
43
examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/NotExample.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,43 @@ | ||
package io.github.rafafrdz.criteria4s.examples | ||
|
||
import io.github.rafafrdz.criteria4s.core._ | ||
import io.github.rafafrdz.criteria4s.dialect.mongodb.MongoDB | ||
import io.github.rafafrdz.criteria4s.examples.datastores._ | ||
import io.github.rafafrdz.criteria4s.extensions._ | ||
import io.github.rafafrdz.criteria4s.functions._ | ||
|
||
object NotExample extends App { | ||
|
||
val simpleNot: Criteria[Postgres] = not(col[Postgres]("a").between(range(1, 10))) | ||
|
||
val symbolNot: Criteria[Postgres] = !!(col[Postgres]("a").between(range(1, 10))) | ||
|
||
def taglessFinalNotExample[ | ||
T <: CriteriaTag: GT: NOT: Show[Column, *]: Show[(Int, Int), *] | ||
]: Criteria[T] = | ||
not(col[T]("column") gt lit(100)) | ||
|
||
def taglessFinalNotSymbolExample[ | ||
T <: CriteriaTag: BETWEEN: NOT: Show[Column, *]: Show[(Int, Int), *] | ||
]: Criteria[T] = | ||
!!(col[T]("column") between range(100, 150)) | ||
|
||
def weirdExampleWithNot[ | ||
T <: CriteriaTag: NOT: GT: LEQ: AND: Show[Column, *]: Show[(Int, Int), *] | ||
]: Criteria[T] = | ||
not(col[T]("column") gt lit(2)) && (col[T]("column") leq lit(10)) | ||
|
||
println(simpleNot) | ||
println(symbolNot) | ||
println(taglessFinalNotExample[Postgres]) | ||
println(taglessFinalNotExample[WeirdDatastore]) | ||
println(taglessFinalNotExample[MongoDB]) | ||
|
||
println(taglessFinalNotSymbolExample[Postgres]) | ||
println(taglessFinalNotSymbolExample[WeirdDatastore]) | ||
println(taglessFinalNotSymbolExample[MongoDB]) | ||
|
||
println(weirdExampleWithNot[Postgres]) | ||
println(weirdExampleWithNot[WeirdDatastore]) | ||
println(weirdExampleWithNot[MongoDB]) | ||
} |
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
Oops, something went wrong.