Try new operation table
This commit is contained in:
37
script/sql/api/1.title.sql
Normal file
37
script/sql/api/1.title.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
drop function if exists get_title;
|
||||
|
||||
create function get_title() returns text as
|
||||
$$
|
||||
select value from title as result;
|
||||
$$
|
||||
language sql;
|
||||
|
||||
|
||||
drop function if exists set_title;
|
||||
|
||||
create function set_title(new_value text) returns json as
|
||||
$$
|
||||
declare
|
||||
old_value text;
|
||||
|
||||
redo_sql text;
|
||||
undo_sql text;
|
||||
redo_cs json;
|
||||
undo_cs json;
|
||||
|
||||
begin
|
||||
select value into old_value from title;
|
||||
|
||||
redo_sql = format('update title set value = ''%s''', new_value);
|
||||
undo_sql = format('update title set value = ''%s''', old_value);
|
||||
redo_cs = format('{"operation": "update", "type": "title", "value": "%s" }', new_value)::json;
|
||||
undo_cs = format('{"operation": "update", "type": "title", "value": "%s" }', old_value)::json;
|
||||
execute add_operation(redo_sql, undo_sql, redo_cs, undo_cs);
|
||||
|
||||
execute redo_sql;
|
||||
|
||||
return redo_cs;
|
||||
|
||||
end;
|
||||
$$
|
||||
language plpgsql;
|
||||
Reference in New Issue
Block a user