WIP on query tests

This commit is contained in:
2025-02-18 17:54:18 -05:00
parent 0b11b803cc
commit 2b6dff9fd3
6 changed files with 173 additions and 50 deletions

View File

@@ -14,7 +14,7 @@ class Comparison<T>(val op: Op, val value: T) {
val toCheck = when (op) {
Op.IN -> {
val values = value as? Collection<*>
if (values.isNullOrEmpty()) "" else values.elementAt(0)
if (values.isNullOrEmpty()) "" else values.elementAt(0)
}
Op.BETWEEN -> (value as Pair<*, *>).first
else -> value

View File

@@ -21,7 +21,11 @@ object Parameters {
fun nameFields(fields: Collection<Field<*>>): Collection<Field<*>> {
val name = ParameterName()
return fields.map {
if (it.name.isBlank()) it.withParameterName(name.derive(null)) else it
if (it.parameterName.isNullOrEmpty() && !listOf(Op.EXISTS, Op.NOT_EXISTS).contains(it.comparison.op)) {
it.withParameterName(name.derive(null))
} else {
it
}
}
}
@@ -75,7 +79,8 @@ object Parameters {
is Int -> stmt.setInt(idx, param.value)
is Long -> stmt.setLong(idx, param.value)
else -> throw DocumentException(
"Number parameter must be Byte, Short, Int, or Long (${param.value::class.simpleName})")
"Number parameter must be Byte, Short, Int, or Long " +
"(${param.value::class.simpleName})")
}
}
ParameterType.STRING -> {

View File

@@ -16,7 +16,7 @@ object Results {
* @param rs A `ResultSet` set to the row with the document to be constructed
* @return The constructed domain item
*/
inline fun <reified TDoc> fromDocument(field: String, rs: ResultSet): TDoc =
inline fun <reified TDoc> fromDocument(field: String, rs: ResultSet) =
Configuration.json.decodeFromString<TDoc>(rs.getString(field))
/**
@@ -25,8 +25,8 @@ object Results {
* @param rs A `ResultSet` set to the row with the document to be constructed<
* @return The constructed domain item
*/
inline fun <reified TDoc> fromData(rs: ResultSet): TDoc =
fromDocument("data", rs)
inline fun <reified TDoc> fromData(rs: ResultSet) =
fromDocument<TDoc>("data", rs)
/**
* Create a list of items for the results of the given command, using the specified mapping function
@@ -36,7 +36,7 @@ object Results {
* @return A list of items from the query's result
* @throws DocumentException If there is a problem executing the query
*/
inline fun <reified TDoc> toCustomList(stmt: PreparedStatement, mapFunc: (ResultSet) -> TDoc): List<TDoc> =
inline fun <reified TDoc> toCustomList(stmt: PreparedStatement, mapFunc: (ResultSet) -> TDoc) =
try {
stmt.executeQuery().use {
val results = mutableListOf<TDoc>()
@@ -55,7 +55,7 @@ object Results {
* @param rs A `ResultSet` set to the row with the count to retrieve
* @return The count from the row
*/
fun toCount(rs: ResultSet): Long =
fun toCount(rs: ResultSet) =
when (Configuration.dialect()) {
Dialect.POSTGRESQL -> rs.getInt("it").toLong()
Dialect.SQLITE -> rs.getLong("it")
@@ -67,7 +67,7 @@ object Results {
* @param rs A `ResultSet` set to the row with the true/false value to retrieve
* @return The true/false value from the row
*/
fun toExists(rs: ResultSet): Boolean =
fun toExists(rs: ResultSet) =
when (Configuration.dialect()) {
Dialect.POSTGRESQL -> rs.getBoolean("it")
Dialect.SQLITE -> toCount(rs) > 0L