test vararg for ExecutableRaw.execute

This commit is contained in:
2023-04-06 21:41:10 +02:00
parent bd473daa6c
commit 56c67981db
3 changed files with 10 additions and 21 deletions

View File

@@ -7,18 +7,6 @@ import kotlin.jvm.Throws
typealias SelectCallback<R> = QueryResult.(R?) -> Unit typealias SelectCallback<R> = QueryResult.(R?) -> Unit
sealed interface ExecutableRaw : Executable { sealed interface ExecutableRaw : Executable {
/**
* Select with one entity as argument
*/
@Throws(DataNotFoundException::class)
fun <R : Any> execute(
sql: String,
typeReference: TypeReference<R>,
value: R,
block: SelectCallback<R> = {}
): R? =
execute(sql, typeReference, listOf(value), block)
/** /**
* Select with [List] of parameters * Select with [List] of parameters
*/ */

View File

@@ -34,14 +34,6 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) {
inline fun <reified E> deserialize(json: String): E? { inline fun <reified E> deserialize(json: String): E? {
return this.mapper.readValue(json) return this.mapper.readValue(json)
} }
fun <E> deserializeList(json: String, valueTypeRef: TypeReference<E>): E {
return mapper.readValue(json, valueTypeRef)
}
inline fun <reified E> deserializeList(json: String): E {
return deserializeList(json, object : TypeReference<E>() {})
}
} }
inline fun <reified E : Any?> QueryResult.deserialize(): E? { inline fun <reified E : Any?> QueryResult.deserialize(): E? {

View File

@@ -109,7 +109,16 @@ class ConnectionTest : TestAbstract() {
@Test @Test
fun `test update Entity`() { fun `test update Entity`() {
val obj = ObjTest("before", id = UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96")) val obj = ObjTest("before", id = UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"))
val objUpdated: ObjTest? = connection.execute("select ?::jsonb || jsonb_build_object('name', 'after');", obj.toTypeReference(), obj) val objUpdated: ObjTest? = connection.execute("select ?::jsonb || jsonb_build_object('name', 'after');", obj.toTypeReference(), listOf(obj))
assertNotNull(objUpdated)
assertEquals(UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"), objUpdated.id)
assertEquals("after", objUpdated.name)
}
@Test
fun `test update Entity with vararg`() {
val obj = ObjTest("before", id = UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"))
val objUpdated: ObjTest? = connection.execute("select :obj::jsonb || jsonb_build_object('name', 'after');", obj.toTypeReference(), "obj" to obj)
assertNotNull(objUpdated) assertNotNull(objUpdated)
assertEquals(UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"), objUpdated.id) assertEquals(UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"), objUpdated.id)
assertEquals("after", objUpdated.name) assertEquals("after", objUpdated.name)