feature: update input with response if input and output is the same object
This commit is contained in:
@@ -44,12 +44,19 @@ class Connection(
|
|||||||
values: List<Any?>,
|
values: List<Any?>,
|
||||||
block: (QueryResult, R?) -> Unit
|
block: (QueryResult, R?) -> Unit
|
||||||
): R? {
|
): R? {
|
||||||
|
val primaryObject = values.firstOrNull {
|
||||||
|
it is EntityI<*> && typeReference.type.typeName == it::class.java.name
|
||||||
|
} as R?
|
||||||
val result = exec(sql, compileArgs(values))
|
val result = exec(sql, compileArgs(values))
|
||||||
val json = result.rows[0].getString(0)
|
val json = result.rows[0].getString(0)
|
||||||
return if (json === null) {
|
return if (json === null) {
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
serializer.deserialize(json, typeReference)
|
if (primaryObject != null) {
|
||||||
|
serializer.deserialize(json, primaryObject)
|
||||||
|
} else {
|
||||||
|
serializer.deserialize(json, typeReference)
|
||||||
|
}
|
||||||
}.also {
|
}.also {
|
||||||
block(result, it)
|
block(result, it)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,19 @@ class RequesterTest: TestAbstract() {
|
|||||||
assertEquals("myName", obj.name)
|
assertEquals("myName", obj.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `call selectOne on function with object`() {
|
||||||
|
val resources = File(this::class.java.getResource("/sql/function").toURI())
|
||||||
|
val obj2 = ObjTest("original")
|
||||||
|
val obj: ObjTest = Requester(getConnextion())
|
||||||
|
.addFunction(resources)
|
||||||
|
.getFunction("test_function_object")
|
||||||
|
.selectOne("resource" to obj2)!!
|
||||||
|
|
||||||
|
assertEquals("changedName", obj.name)
|
||||||
|
assertEquals("changedName", obj2.name)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `call selectOne on query`() {
|
fun `call selectOne on query`() {
|
||||||
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
val resources = File(this::class.java.getResource("/sql/query").toURI())
|
||||||
|
|||||||
@@ -63,4 +63,13 @@ BEGIN
|
|||||||
INTO result, total
|
INTO result, total
|
||||||
LIMIT "limit" OFFSET "offset";
|
LIMIT "limit" OFFSET "offset";
|
||||||
END;
|
END;
|
||||||
$$
|
$$;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION test_function_object (inout resource json)
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
resource = json_build_object('id', 1, 'name', 'changedName');
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION test_function_object (inout resource json)
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
resource = json_build_object('id', 1, 'name', 'changedName');
|
||||||
|
END;
|
||||||
|
$$
|
||||||
Reference in New Issue
Block a user