Add common throwaway db; all ITs now work in both
This commit is contained in:
@@ -39,6 +39,30 @@ object Parameters {
|
||||
inline fun <reified T> json(name: String, value: T) =
|
||||
Parameter(name, ParameterType.JSON, Configuration.json.encodeToString(value))
|
||||
|
||||
/**
|
||||
* Add field parameters to the given set of parameters
|
||||
*
|
||||
* @param fields The fields being compared in the query
|
||||
* @param existing Any existing parameters for the query (optional, defaults to empty collection)
|
||||
* @return A collection of parameters for the query
|
||||
*/
|
||||
fun addFields(
|
||||
fields: Collection<Field<*>>,
|
||||
existing: MutableCollection<Parameter<*>> = mutableListOf()
|
||||
): MutableCollection<Parameter<*>> {
|
||||
existing.addAll(
|
||||
fields
|
||||
.filter { it.comparison.op != Op.EXISTS && it.comparison.op != Op.NOT_EXISTS }
|
||||
.map {
|
||||
Parameter(
|
||||
it.parameterName!!,
|
||||
if (it.comparison.isNumeric) ParameterType.NUMBER else ParameterType.STRING,
|
||||
it.comparison.value
|
||||
)
|
||||
})
|
||||
return existing
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the parameter names in the query with question marks
|
||||
*
|
||||
@@ -47,7 +71,7 @@ object Parameters {
|
||||
* @return The query, with name parameters changed to `?`s
|
||||
*/
|
||||
fun replaceNamesInQuery(query: String, parameters: Collection<Parameter<*>>) =
|
||||
parameters.sortedByDescending { it.name.length }.fold(query) { acc, param -> acc.replace(param.name, "?") }.also(::println)
|
||||
parameters.sortedByDescending { it.name.length }.fold(query) { acc, param -> acc.replace(param.name, "?") }
|
||||
|
||||
/**
|
||||
* Apply the given parameters to the given query, returning a prepared statement
|
||||
|
||||
Reference in New Issue
Block a user