WIP: Compiled SQL function #33

Draft
flecomte wants to merge 37 commits from compiled_sql_function into master
3 changed files with 10 additions and 21 deletions
Showing only changes of commit 56c67981db - Show all commits

View File

@@ -7,18 +7,6 @@ import kotlin.jvm.Throws
typealias SelectCallback<R> = QueryResult.(R?) -> Unit
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
*/

View File

@@ -34,14 +34,6 @@ class Serializer(val mapper: ObjectMapper = jacksonObjectMapper()) {
inline fun <reified E> deserialize(json: String): E? {
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? {

View File

@@ -109,7 +109,16 @@ class ConnectionTest : TestAbstract() {
@Test
fun `test update Entity`() {
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)
assertEquals(UUID.fromString("1e5f5d41-6d14-4007-897b-0ed2616bec96"), objUpdated.id)
assertEquals("after", objUpdated.name)