-
-
Save DRMacIver/7aa8ea79e2e6a68bc074 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table unfiltered_posts(id int primary key default nextval('post_ids'), | |
body text, | |
deleted boolean not null default false); | |
create view posts as select * from unfiltered_posts where not deleted; | |
create or replace rule insert_into_posts as | |
on insert to posts do instead | |
insert into unfiltered_posts | |
values(coalesce(NEW.id, nextval('post_ids')), | |
NEW.body, | |
coalesce(NEW.deleted, false)); | |
create or replace rule update_to_posts as | |
on update to posts do instead | |
update unfiltered_posts | |
set id = coalesce(NEW.id, OLD.id), | |
body = coalesce(NEW.body, OLD.body), | |
deleted = coalesce(NEW.deleted, OLD.deleted) | |
where id = OLD.id; | |
create or replace rule delete_posts as | |
on delete to posts do instead | |
update unfiltered_posts | |
set deleted = true where id = OLD.id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment