-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use more refined array column types and pass arrays instead of lists/…
…iterables, getting `testEqAny` (for an array of strings) to work on PostgreSQL (`postgres` and `postgresNG`)
- Loading branch information
Showing
5 changed files
with
64 additions
and
45 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
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
40 changes: 26 additions & 14 deletions
40
exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/ops/AllAnyOps.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 |
---|---|---|
@@ -1,33 +1,45 @@ | ||
package org.jetbrains.exposed.sql.ops | ||
|
||
import org.jetbrains.exposed.sql.ArrayColumnType | ||
import org.jetbrains.exposed.sql.IColumnType | ||
import org.jetbrains.exposed.sql.OneDimArrayColumnType | ||
import org.jetbrains.exposed.sql.Op | ||
import org.jetbrains.exposed.sql.QueryBuilder | ||
import org.jetbrains.exposed.sql.toColumnType | ||
import kotlin.reflect.KClass | ||
|
||
class AllAnyOp<T>(val opType: OpType, val elementType: IColumnType, val list: Iterable<T>, val toTypedArray: List<T>.() -> Any) : Op<T>() { | ||
// TODO remove | ||
/* | ||
init { | ||
require(list.any()) | ||
val type = list.asSequence().filter { it !== null }::class | ||
require(list.all { it === null || it!!::class == type }) | ||
} | ||
*/ | ||
|
||
abstract class AllAnyOp<T>(val list: Iterable<T>) : Op<T>() { | ||
enum class OpType { | ||
All, Any | ||
} | ||
|
||
abstract fun isAllOrAny(): OpType | ||
|
||
override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder { | ||
+when (isAllOrAny()) { | ||
+when (opType) { | ||
OpType.All -> "ALL" | ||
OpType.Any -> "ANY" | ||
} | ||
+'(' | ||
//+"ARRAY[" // This syntax is for PostgresSQL. | ||
registerArgument(ArrayColumnType<T>(), list) | ||
//+"]" | ||
// +"ARRAY[" // This syntax is for PostgresSQL. | ||
val array = list.toList().toTypedArray() | ||
registerArgument(OneDimArrayColumnType(elementType), array) | ||
// +"]" | ||
+')' | ||
} | ||
} | ||
|
||
class AllOp<T>(list: Iterable<T>) : AllAnyOp<T>(list) { | ||
override fun isAllOrAny(): OpType = OpType.All | ||
} | ||
// TODO remove | ||
/* | ||
inline fun <reified T> AllAnyOp(opType: AllAnyOp.OpType, list: Iterable<T>) = | ||
AllAnyOp(opType, (T::class as KClass<*>).toColumnType(), list) | ||
*/ | ||
|
||
class AnyOp<T>(list: Iterable<T>) : AllAnyOp<T>(list) { | ||
override fun isAllOrAny(): OpType = OpType.Any | ||
} | ||
inline fun <reified T> AllAnyOp(opType: AllAnyOp.OpType, list: Iterable<T>) = | ||
AllAnyOp(opType, (T::class as KClass<*>).toColumnType(), list) { this.toTypedArray() } |