dev.fuelyour.vertxkuickstartcore.tools.VertxNamedToPositionalSqlConverter.kt Maven / Gradle / Ivy
package dev.fuelyour.vertxkuickstartcore.tools
import dev.fuelyour.namedToPositionalSqlParams.converter.convertNamedToPositional
import dev.fuelyour.namedToPositionalSqlParams.converter.prepareNamedAsPositional
import io.vertx.sqlclient.Tuple
data class PositionalSql(val sql: String, val params: Tuple)
data class PreparedPositionalSql(
val sql: String,
val paramNames: List,
val convertParams: (params: Map) -> Tuple
) {
fun toPositional(params: Map): PositionalSql =
PositionalSql(sql, convertParams(params))
}
fun toPositional(sql: String, params: Map): PositionalSql =
convertNamedToPositional(sql, params).let { (sql, params) ->
PositionalSql(sql, Tuple.wrap(params))
}
fun preparePositional(
sql: String,
paramNames: Set? = null
): PreparedPositionalSql =
prepareNamedAsPositional(sql, paramNames).let { prepared ->
PreparedPositionalSql(prepared.sql, prepared.paramNames) { params ->
Tuple.wrap(prepared.convertParams(params))
}
}