Refine api style for change set
This commit is contained in:
37
script/sql/api/api.sql
Normal file
37
script/sql/api/api.sql
Normal 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;
|
||||
Reference in New Issue
Block a user