Refine api style for change set

This commit is contained in:
WQY\qiong
2022-10-09 23:25:31 +08:00
parent 69db29d981
commit 231304f73a
5 changed files with 112 additions and 41 deletions

37
script/sql/api/api.sql Normal file
View File

@@ -0,0 +1,37 @@
drop function if exists execute_command;
drop function if exists execute_update;
create function execute_update(cs jsonb) returns jsonb as
$$
declare
begin
assert cs->>'operation' = 'update';
case cs->>'type'
when 'title' then
return update_title(cs);
else
return '{}'::jsonb;
end case;
end;
$$
language plpgsql;
create function execute_command(cs jsonb) returns jsonb as
$$
declare
begin
case cs->>'operation'
when 'add' then
return '{}'::jsonb;
when 'update' then
return execute_update(cs);
when 'delete' then
return '{}'::jsonb;
else
return '{}'::jsonb;
end case;
end;
$$
language plpgsql;