feature #4: create function for comment
This commit is contained in:
25
resources/functions/comment/comment.sql
Normal file
25
resources/functions/comment/comment.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
create or replace function comment(reference regclass, target_id uuid, citizen_id uuid, content text, parent_id uuid default null, out id uuid)
|
||||
language plpgsql as
|
||||
$$
|
||||
declare
|
||||
_citizen_id alias for citizen_id;
|
||||
_target_id alias for target_id;
|
||||
_content alias for content;
|
||||
_parent_id alias for parent_id;
|
||||
_id alias for id;
|
||||
begin
|
||||
if reference = 'article'::regclass then
|
||||
insert into comment_on_article (citizen_id, target_id, content, parent_id)
|
||||
values (_citizen_id, _target_id, _content, _parent_id)
|
||||
returning comment_on_article.id into _id;
|
||||
elseif reference = 'constitution'::regclass then
|
||||
insert into comment_on_constitution (citizen_id, target_id, content, parent_id)
|
||||
values (_citizen_id, _target_id, _content, _parent_id)
|
||||
returning comment_on_constitution.id into _id;
|
||||
else
|
||||
raise exception '% no implemented', reference::text;
|
||||
end if;
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- drop function if exists comment(regclass, uuid, uuid, text, uuid);
|
||||
20
resources/functions/comment/edit_comment.sql
Normal file
20
resources/functions/comment/edit_comment.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
create or replace function edit_comment(reference regclass, id uuid, content text) returns void
|
||||
language plpgsql as
|
||||
$$
|
||||
declare
|
||||
_id alias for id;
|
||||
_content alias for content;
|
||||
begin
|
||||
if reference = 'article'::regclass then
|
||||
update comment_on_article c set
|
||||
content = _content
|
||||
where c.id = _id;
|
||||
elseif reference = 'constitution'::regclass then
|
||||
update comment_on_constitution c set
|
||||
content = _content
|
||||
where c.id = _id;
|
||||
end if;
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- drop function if exists edit_comment(regclass, uuid, uuid, text, uuid);
|
||||
Reference in New Issue
Block a user