Skip to content

Commit

Permalink
fix projects operator
Browse files Browse the repository at this point in the history
Signed-off-by: Yuchen Liang <[email protected]>
  • Loading branch information
yliang412 committed Feb 3, 2025
1 parent fc9b050 commit 8bad99c
Showing 1 changed file with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ BEGIN
UPDATE OR REPLACE projects SET child_group_id = NEW.representative_group_id WHERE child_group_id = OLD.representative_group_id;
END;

CREATE VIEW project_fields AS
SELECT
logical_expressions.id as logical_expression_id,
json_each.value as field_group_id
FROM projects, json_each(fields_group_ids);


-- Approach 1:
CREATE TRIGGER update_projects_scalar_group_ids
AFTER UPDATE OF representative_group_id ON scalar_groups
Expand All @@ -51,22 +44,28 @@ BEGIN
END;

-- Approach 2:
CREATE TRIGGER update_projects_scalar_group_ids
AFTER UPDATE OF representative_group_id ON scalar_groups
BEGIN
UPDATE project_fields SET field_group_id = NEW.representative_group_id WHERE field_group_id = OLD.representative_group_id;
END;
-- CREATE VIEW project_fields AS
-- SELECT
-- logical_expressions.id as logical_expression_id,
-- json_each.value as field_group_id
-- FROM projects, json_each(fields_group_ids);


CREATE TRIGGER update_project_fields
INSTEAD OF UPDATE ON project_fields
BEGIN
UPDATE projects SET fields_group_ids = (
SELECT json_group_array(
CASE
WHEN value = OLD.field_group_id THEN NEW.field_group_id
ELSE value
END
) FROM json_each(fields_group_ids)
) WHERE logical_expression_id = OLD.logical_expression_id;
END;
-- CREATE TRIGGER update_projects_scalar_group_ids
-- AFTER UPDATE OF representative_group_id ON scalar_groups
-- BEGIN
-- UPDATE project_fields SET field_group_id = NEW.representative_group_id WHERE field_group_id = OLD.representative_group_id;
-- END;

-- CREATE TRIGGER update_project_fields
-- INSTEAD OF UPDATE ON project_fields
-- BEGIN
-- UPDATE projects SET fields_group_ids = (
-- SELECT json_group_array(
-- CASE
-- WHEN value = OLD.field_group_id THEN NEW.field_group_id
-- ELSE value
-- END
-- ) FROM json_each(fields_group_ids)
-- ) WHERE logical_expression_id = OLD.logical_expression_id;
-- END;

0 comments on commit 8bad99c

Please sign in to comment.