Remove research code

This commit is contained in:
WQY\qiong
2022-10-14 09:27:18 +08:00
parent 231304f73a
commit 200aaaca99
4 changed files with 0 additions and 202 deletions

View File

@@ -1,71 +0,0 @@
drop function if exists update_title;
drop function if exists get_title_update_template;
drop function if exists get_title;
drop function if exists get_title_schema;
create function get_title_schema() returns jsonb as
$$
declare
begin
return '{"value": {"opetional": false, "readonly": false}}'::jsonb;
end;
$$
language plpgsql;
create function get_title() returns jsonb as
$$
declare
v_value text;
begin
select value into v_value from title;
return format('{"value": "%s"}', v_value)::jsonb;
end;
$$
language plpgsql;
create function get_title_update_template() returns jsonb as
$$
declare
begin
return '{"operation": "update", "type": "title", "value": ""}'::jsonb;
end;
$$
language plpgsql;
create function update_title(new jsonb) returns jsonb as
$$
declare
old jsonb;
redo_sql text;
undo_sql text;
redo_cs jsonb;
undo_cs jsonb;
begin
assert new->>'operation' = 'update';
assert new->>'type' = 'title';
assert new ? 'value';
old := get_title();
if old->>'value' = new->>'value' then
return '{}'::jsonb;
end if;
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')::jsonb;
undo_cs := format('{"operation": "update", "type": "title", "value": "%s" }', old->>'value')::jsonb;
execute redo_sql;
execute add_operation(redo_sql, undo_sql, redo_cs, undo_cs);
return redo_cs;
end;
$$
language plpgsql;

View File

@@ -1,37 +0,0 @@
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;

View File

@@ -1,84 +0,0 @@
drop function if exists execute_undo;
drop function if exists add_operation;
drop function if exists get_current_operation;
create function get_current_operation() returns integer as
$$
select id from current_operation as result;
$$
language sql;
create function add_operation(redo_sql text, undo_sql text, redo_cs jsonb, undo_cs jsonb) returns void as
$$
declare
parent_id integer;
op_id integer;
begin
parent_id := get_current_operation();
insert into operation (id, redo, undo, parent, redo_change_set, undo_change_set)
values (default, redo_sql, undo_sql, parent_id, redo_cs, undo_cs);
select max(id) into op_id from operation;
update current_operation set id = op_id where id = parent_id;
end;
$$
language plpgsql;
create function execute_undo(discard boolean) returns jsonb as
$$
#print_strict_params on
declare
op_row operation%ROWTYPE;
begin
select * into strict op_row from operation where id = get_current_operation();
if op_row.undo = '' then
return '{}'::jsonb;
end if;
execute op_row.undo;
-- update foreign key
update current_operation set id = op_row.parent where id = op_row.id;
if discard then
-- update foreign key
update operation set redo_child = null where id = op_row.parent;
-- on delete cascade => child & snapshot
delete from operation where id = op_row.id;
else
update operation set redo_child = op_row.id where id = op_row.parent;
end if;
return op_row.undo_change_set;
end;
$$
language plpgsql;
-- create function execute_redo() returns jsonb as
-- $$
-- #print_strict_params on
--
-- declare
-- op_id integer;
-- redo_c integer;
-- redo_row operation%ROWTYPE;
--
-- begin
-- op_id := get_current_operation();
--
-- select redo_child into redo_c from operation where id = op_id;
--
-- end;
-- $$
-- language plpgsql;

View File

@@ -33,12 +33,6 @@ sql_create = [
"sql/create/operation.sql"
]
sql_api = [
"sql/api/operation.sql",
"sql/api/1.title.sql",
"sql/api/api.sql"
]
sql_drop = [
"sql/drop/operation.sql",
"sql/drop/28.end.sql",
@@ -82,10 +76,6 @@ def create_template():
with open(sql, "r") as f:
cur.execute(f.read())
print(f'executed {sql}')
for sql in sql_api:
with open(sql, "r") as f:
cur.execute(f.read())
print(f'executed {sql}')
conn.commit()
def have_template():