-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from ergon/feature/dope-229-existence-membersh…
…ip-predicates DOPE-229: existence and membership predicates
- Loading branch information
Showing
23 changed files
with
1,171 additions
and
29 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
22 changes: 22 additions & 0 deletions
22
.../kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/collection/ExistsExpression.kt
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,22 @@ | ||
package ch.ergon.dope.resolvable.expression.unaliased.type.collection | ||
|
||
import ch.ergon.dope.DopeQuery | ||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType | ||
import ch.ergon.dope.validtype.ArrayType | ||
import ch.ergon.dope.validtype.BooleanType | ||
import ch.ergon.dope.validtype.ValidType | ||
|
||
class ExistsExpression<T : ValidType>(private val array: TypeExpression<ArrayType<T>>) : TypeExpression<BooleanType> { | ||
override fun toDopeQuery(): DopeQuery { | ||
val arrayDopeQuery = array.toDopeQuery() | ||
return DopeQuery( | ||
queryString = "EXISTS ${arrayDopeQuery.queryString}", | ||
parameters = arrayDopeQuery.parameters, | ||
) | ||
} | ||
} | ||
|
||
fun <T : ValidType> exists(array: TypeExpression<ArrayType<T>>) = ExistsExpression(array) | ||
|
||
fun <T : ValidType> exists(array: Collection<TypeExpression<T>>) = exists(array.toDopeType()) |
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
15 changes: 15 additions & 0 deletions
15
...lin/ch/ergon/dope/resolvable/expression/unaliased/type/collection/MembershipExpression.kt
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,15 @@ | ||
package ch.ergon.dope.resolvable.expression.unaliased.type.collection | ||
|
||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.operator.InfixOperator | ||
import ch.ergon.dope.validtype.ArrayType | ||
import ch.ergon.dope.validtype.BooleanType | ||
import ch.ergon.dope.validtype.ValidType | ||
|
||
sealed class MembershipExpression<T : ValidType>( | ||
value: TypeExpression<T>, | ||
symbol: String, | ||
collection: TypeExpression<ArrayType<T>>, | ||
) : TypeExpression<BooleanType>, InfixOperator(value, symbol, collection) { | ||
override fun toDopeQuery() = toInfixDopeQuery() | ||
} |
38 changes: 38 additions & 0 deletions
38
...n/kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/collection/NotInExpression.kt
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,38 @@ | ||
package ch.ergon.dope.resolvable.expression.unaliased.type.collection | ||
|
||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType | ||
import ch.ergon.dope.validtype.ArrayType | ||
import ch.ergon.dope.validtype.BooleanType | ||
import ch.ergon.dope.validtype.NumberType | ||
import ch.ergon.dope.validtype.StringType | ||
import ch.ergon.dope.validtype.ValidType | ||
|
||
class NotInExpression<T : ValidType>( | ||
value: TypeExpression<T>, | ||
collection: TypeExpression<ArrayType<T>>, | ||
) : MembershipExpression<T>(value, "NOT IN", collection) | ||
|
||
fun <T : ValidType> TypeExpression<T>.notInArray(array: TypeExpression<ArrayType<T>>): NotInExpression<T> = | ||
NotInExpression(this, array) | ||
|
||
fun Number.notInArray(array: TypeExpression<ArrayType<NumberType>>): NotInExpression<NumberType> = | ||
toDopeType().notInArray(array) | ||
|
||
fun String.notInArray(array: TypeExpression<ArrayType<StringType>>): NotInExpression<StringType> = | ||
toDopeType().notInArray(array) | ||
|
||
fun Boolean.notInArray(array: TypeExpression<ArrayType<BooleanType>>): NotInExpression<BooleanType> = | ||
toDopeType().notInArray(array) | ||
|
||
fun <T : ValidType> TypeExpression<T>.notInArray(array: Collection<TypeExpression<T>>): NotInExpression<T> = | ||
this.notInArray(array.toDopeType()) | ||
|
||
fun Number.notInArray(array: Collection<TypeExpression<NumberType>>): NotInExpression<NumberType> = | ||
notInArray(array.toDopeType()) | ||
|
||
fun String.notInArray(array: Collection<TypeExpression<StringType>>): NotInExpression<StringType> = | ||
notInArray(array.toDopeType()) | ||
|
||
fun Boolean.notInArray(array: Collection<TypeExpression<BooleanType>>): NotInExpression<BooleanType> = | ||
notInArray(array.toDopeType()) |
37 changes: 37 additions & 0 deletions
37
...tlin/ch/ergon/dope/resolvable/expression/unaliased/type/collection/NotWithinExpression.kt
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,37 @@ | ||
package ch.ergon.dope.resolvable.expression.unaliased.type.collection | ||
|
||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType | ||
import ch.ergon.dope.validtype.ArrayType | ||
import ch.ergon.dope.validtype.BooleanType | ||
import ch.ergon.dope.validtype.NumberType | ||
import ch.ergon.dope.validtype.StringType | ||
import ch.ergon.dope.validtype.ValidType | ||
|
||
class NotWithinExpression<T : ValidType>( | ||
value: TypeExpression<T>, | ||
collection: TypeExpression<ArrayType<T>>, | ||
) : MembershipExpression<T>(value, "NOT WITHIN", collection) | ||
|
||
fun <T : ValidType> TypeExpression<T>.notWithinArray(collection: TypeExpression<ArrayType<T>>) = NotWithinExpression(this, collection) | ||
|
||
fun Number.notWithinArray(collection: TypeExpression<ArrayType<NumberType>>): NotWithinExpression<NumberType> = | ||
toDopeType().notWithinArray(collection) | ||
|
||
fun String.notWithinArray(collection: TypeExpression<ArrayType<StringType>>): NotWithinExpression<StringType> = | ||
toDopeType().notWithinArray(collection) | ||
|
||
fun Boolean.notWithinArray(collection: TypeExpression<ArrayType<BooleanType>>): NotWithinExpression<BooleanType> = | ||
toDopeType().notWithinArray(collection) | ||
|
||
fun <T : ValidType> TypeExpression<T>.notWithinArray(collection: Collection<TypeExpression<T>>): NotWithinExpression<T> = | ||
this.notWithinArray(collection.toDopeType()) | ||
|
||
fun Number.notWithinArray(collection: Collection<TypeExpression<NumberType>>): NotWithinExpression<NumberType> = | ||
notWithinArray(collection.toDopeType()) | ||
|
||
fun String.notWithinArray(collection: Collection<TypeExpression<StringType>>): NotWithinExpression<StringType> = | ||
notWithinArray(collection.toDopeType()) | ||
|
||
fun Boolean.notWithinArray(collection: Collection<TypeExpression<BooleanType>>): NotWithinExpression<BooleanType> = | ||
notWithinArray(collection.toDopeType()) |
6 changes: 3 additions & 3 deletions
6
...ed/type/relational/SatisfiesExpression.kt → ...ed/type/collection/SatisfiesExpression.kt
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
38 changes: 38 additions & 0 deletions
38
.../kotlin/ch/ergon/dope/resolvable/expression/unaliased/type/collection/WithinExpression.kt
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,38 @@ | ||
package ch.ergon.dope.resolvable.expression.unaliased.type.collection | ||
|
||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType | ||
import ch.ergon.dope.validtype.ArrayType | ||
import ch.ergon.dope.validtype.BooleanType | ||
import ch.ergon.dope.validtype.NumberType | ||
import ch.ergon.dope.validtype.StringType | ||
import ch.ergon.dope.validtype.ValidType | ||
|
||
class WithinExpression<T : ValidType>( | ||
value: TypeExpression<T>, | ||
collection: TypeExpression<ArrayType<T>>, | ||
) : MembershipExpression<T>(value, "WITHIN", collection) | ||
|
||
fun <T : ValidType> TypeExpression<T>.withinArray(array: TypeExpression<ArrayType<T>>): WithinExpression<T> = | ||
WithinExpression(this, array) | ||
|
||
fun Number.withinArray(array: TypeExpression<ArrayType<NumberType>>): WithinExpression<NumberType> = | ||
toDopeType().withinArray(array) | ||
|
||
fun String.withinArray(array: TypeExpression<ArrayType<StringType>>): WithinExpression<StringType> = | ||
toDopeType().withinArray(array) | ||
|
||
fun Boolean.withinArray(array: TypeExpression<ArrayType<BooleanType>>): WithinExpression<BooleanType> = | ||
toDopeType().withinArray(array) | ||
|
||
fun <T : ValidType> TypeExpression<T>.withinArray(array: Collection<TypeExpression<T>>): WithinExpression<T> = | ||
this.withinArray(array.toDopeType()) | ||
|
||
fun Number.withinArray(array: Collection<TypeExpression<NumberType>>): WithinExpression<NumberType> = | ||
withinArray(array.toDopeType()) | ||
|
||
fun String.withinArray(array: Collection<TypeExpression<StringType>>): WithinExpression<StringType> = | ||
withinArray(array.toDopeType()) | ||
|
||
fun Boolean.withinArray(array: Collection<TypeExpression<BooleanType>>): WithinExpression<BooleanType> = | ||
withinArray(array.toDopeType()) |
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
67 changes: 67 additions & 0 deletions
67
core/src/test/kotlin/ch/ergon/dope/operators/collection/ExistsExpressionTest.kt
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,67 @@ | ||
package ch.ergon.dope.operators.collection | ||
|
||
import ch.ergon.dope.DopeQuery | ||
import ch.ergon.dope.helper.someNumberArrayField | ||
import ch.ergon.dope.helper.someNumberField | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.ParameterManager | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.asParameter | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.collection.ExistsExpression | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.collection.exists | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class ExistsExpressionTest { | ||
@BeforeEach | ||
fun reset() { | ||
ParameterManager.resetCounter() | ||
} | ||
|
||
@Test | ||
fun `should support EXISTS expression`() { | ||
val expected = DopeQuery( | ||
"EXISTS `numberArrayField`", | ||
emptyMap(), | ||
) | ||
val underTest = ExistsExpression(someNumberArrayField()) | ||
|
||
val actual = underTest.toDopeQuery() | ||
|
||
assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `should support EXISTS expression with parameter`() { | ||
val parameterValue = listOf(1, 2, 3) | ||
val expected = DopeQuery( | ||
"EXISTS $1", | ||
mapOf("$1" to parameterValue), | ||
) | ||
val underTest = ExistsExpression(parameterValue.asParameter()) | ||
|
||
val actual = underTest.toDopeQuery() | ||
|
||
assertEquals(expected, actual) | ||
} | ||
|
||
@Test | ||
fun `should support EXISTS extension`() { | ||
val array = someNumberArrayField() | ||
val expected = ExistsExpression(array) | ||
|
||
val actual = exists(array) | ||
|
||
assertEquals(expected.toDopeQuery(), actual.toDopeQuery()) | ||
} | ||
|
||
@Test | ||
fun `should support EXISTS extension collection`() { | ||
val array = listOf(someNumberField(), someNumberField()) | ||
val expected = ExistsExpression(array.toDopeType()) | ||
|
||
val actual = exists(array) | ||
|
||
assertEquals(expected.toDopeQuery(), actual.toDopeQuery()) | ||
} | ||
} |
Oops, something went wrong.