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;
