WIP: Compiled SQL function #33

Draft
flecomte wants to merge 37 commits from compiled_sql_function into master
10 changed files with 57 additions and 50 deletions
Showing only changes of commit 2cd69d4501 - Show all commits

View File

@@ -278,7 +278,7 @@ class RequesterTest : TestAbstract() {
fun `call exec on function with pair as arguments`() { fun `call exec on function with pair as arguments`() {
val resources = this::class.java.getResource("/sql/function/Test")?.toURI() val resources = this::class.java.getResource("/sql/function/Test")?.toURI()
val result = Requester(connection, functionsDirectory = resources) val result = Requester(connection, functionsDirectory = resources)
.getFunction("function_void") .getFunction("test_function_void")
.exec("name" to "test") .exec("name" to "test")
assertEquals(1, result.rowsAffected) assertEquals(1, result.rowsAffected)

View File

@@ -74,7 +74,7 @@ BEGIN
END; END;
$$; $$;
CREATE OR REPLACE FUNCTION function_void (name text default 'plop') returns void CREATE OR REPLACE FUNCTION test_function_void (name text default 'plop') returns void
LANGUAGE plpgsql LANGUAGE plpgsql
AS AS
$$ $$

View File

@@ -1,8 +0,0 @@
CREATE OR REPLACE FUNCTION test_function (name text default 'plop', IN hi text default 'hello', out result json)
LANGUAGE plpgsql
AS
$$
BEGIN
result = json_build_object('id', '457daad5-4f1b-4eb7-80ec-6882adb8cc7d', 'name', name);
END;
$$

View File

@@ -1,8 +0,0 @@
CREATE OR REPLACE FUNCTION function_void (name text default 'plop') returns void
LANGUAGE plpgsql
AS
$$
BEGIN
PERFORM 1;
END;
$$;

View File

@@ -0,0 +1,8 @@
create or replace function test_function(name text default 'plop', in hi text default 'hello', out result json)
language plpgsql
as
$$
begin
result = json_build_object('id', '457daad5-4f1b-4eb7-80ec-6882adb8cc7d', 'name', name);
end;
$$

View File

@@ -1,4 +1,4 @@
CREATE OR REPLACE FUNCTION function_multiparam ( create or replace function test_function_multiparam(
name varchar(45) default 'plop', name varchar(45) default 'plop',
numeric(4, 5), numeric(4, 5),
num float(5), num float(5),
@@ -13,7 +13,7 @@ CREATE OR REPLACE FUNCTION function_multiparam (
num10 double precision, num10 double precision,
num11 smallserial, num11 smallserial,
num12 serial, num12 serial,
"num13" bigserial, num13 bigserial,
num14 serial, num14 serial,
num15 money, num15 money,
num16 character varying(789), num16 character varying(789),
@@ -25,10 +25,10 @@ CREATE OR REPLACE FUNCTION function_multiparam (
num20 anyelement, num20 anyelement,
num21 anyarray num21 anyarray
) )
LANGUAGE plpgsql language plpgsql
AS as
$$ $$
BEGIN begin
PERFORM 1; perform 1;
END; end;
$$; $$;

View File

@@ -1,11 +1,11 @@
CREATE OR REPLACE FUNCTION test_function_multiple (name text default 'plop', IN hi text default 'hello', out result json) create or replace function test_function_multiple(name text default 'plop', in hi text default 'hello', out result json)
LANGUAGE plpgsql language plpgsql
AS as
$$ $$
BEGIN begin
result = json_build_array( result = json_build_array(
json_build_object('id', '457daad5-4f1b-4eb7-80ec-6882adb8cc7d', 'name', name), json_build_object('id', '457daad5-4f1b-4eb7-80ec-6882adb8cc7d', 'name', name),
json_build_object('id', '8d20abb0-7f77-4b6c-9991-44acd3c88faa', 'name', hi) json_build_object('id', '8d20abb0-7f77-4b6c-9991-44acd3c88faa', 'name', hi)
); );
END; end;
$$ $$

View File

@@ -1,8 +1,8 @@
CREATE OR REPLACE FUNCTION test_function_object (inout resource json) create or replace function test_function_object(inout resource json)
LANGUAGE plpgsql language plpgsql
AS as
$$ $$
BEGIN begin
resource = json_build_object('id', '1e5f5d41-6d14-4007-897b-0ed2616bec96', 'name', 'changedName'); resource = json_build_object('id', '1e5f5d41-6d14-4007-897b-0ed2616bec96', 'name', 'changedName');
END; end;
$$ $$

View File

@@ -1,14 +1,21 @@
CREATE OR REPLACE FUNCTION test_function_paginated (name text default 'plop', IN "limit" int default 10, IN "offset" int default 0, out result json, out total int) create or replace function test_function_paginated(
LANGUAGE plpgsql name text default 'plop',
AS in "limit" int default 10,
in "offset" int default 0,
out result json,
out total int
)
language plpgsql
as
$$ $$
BEGIN begin
SELECT json_build_array( select
json_build_array(
json_build_object('id', '457daad5-4f1b-4eb7-80ec-6882adb8cc7d', 'name', name::text), json_build_object('id', '457daad5-4f1b-4eb7-80ec-6882adb8cc7d', 'name', name::text),
json_build_object('id', '8d20abb0-7f77-4b6c-9991-44acd3c88faa', 'name', name::text || '-2') json_build_object('id', '8d20abb0-7f77-4b6c-9991-44acd3c88faa', 'name', name::text || '-2')
), ),
10 10
INTO result, total into result, total
LIMIT "limit" OFFSET "offset"; limit "limit" offset "offset";
END; end;
$$ $$

View File

@@ -0,0 +1,8 @@
create or replace function test_function_void(name text default 'plop') returns void
language plpgsql
as
$$
begin
perform 1;
end;
$$;