add Connection.selectAny()

This commit is contained in:
2023-04-05 23:12:08 +02:00
parent 90d5f6e0d7
commit 79d2e52978
5 changed files with 33 additions and 1 deletions

View File

@@ -79,6 +79,15 @@ sealed interface EmbedExecutable {
): List<R> = ): List<R> =
select(typeReference, values.toMap(), block) select(typeReference, values.toMap(), block)
/**
* Select Multiple or One [EntityI] with multiple [Pair] of parameters
*/
fun <R : Any?> selectAny(
typeReference: TypeReference<R>,
values: Map<String, Any?>,
block: QueryResult.(R) -> Unit = {}
): R
/* Select Paginated */ /* Select Paginated */
/** /**

View File

@@ -74,6 +74,16 @@ interface Executable {
block: SelectCallback<R> = {} block: SelectCallback<R> = {}
): List<R> ): List<R>
/**
* Select Multiple or One [EntityI] with [Map] of parameters
*/
fun <R : Any?> selectAny(
sql: String,
typeReference: TypeReference<R>,
values: Map<String, Any?>,
block: QueryResult.(R) -> Unit = {}
): R
/** /**
* Select Multiple [EntityI] with multiple [Pair] of parameters * Select Multiple [EntityI] with multiple [Pair] of parameters
*/ */

View File

@@ -56,6 +56,13 @@ class Function(val definition: Function, override val connection: Connection) :
): List<R> = ): List<R> =
connection.select(compileSql(values), typeReference, values, block) connection.select(compileSql(values), typeReference, values, block)
override fun <R : Any?> selectAny(
typeReference: TypeReference<R>,
values: Map<String, Any?>,
block: QueryResult.(R) -> Unit
): R =
connection.selectAny(compileSql(values.toMap()), typeReference, values.toMap(), block)
/* Select Paginated */ /* Select Paginated */
/** /**

View File

@@ -67,6 +67,12 @@ class Query(override val name: String, private val sql: String, override val con
): Paginated<R> = ): Paginated<R> =
connection.select(sql, page, limit, typeReference, values, block) connection.select(sql, page, limit, typeReference, values, block)
override fun <R> selectAny(
typeReference: TypeReference<R>,
values: Map<String, Any?>,
block: QueryResult.(R) -> Unit
): R = connection.selectAny(sql, typeReference, values.toMap(), block)
/* Execute function without treatments */ /* Execute function without treatments */
override fun exec(values: List<Any?>): QueryResult = connection.exec(sql, values) override fun exec(values: List<Any?>): QueryResult = connection.exec(sql, values)

View File

@@ -28,7 +28,7 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) {
} }
fun <E> deserialize(json: String, valueTypeRef: TypeReference<E>): E { fun <E> deserialize(json: String, valueTypeRef: TypeReference<E>): E {
return this.mapper.readValue(json, valueTypeRef) return mapper.readValue(json, valueTypeRef)
} }
inline fun <reified E> deserialize(json: String): E? { inline fun <reified E> deserialize(json: String): E? {