1 create view community_view as
5 (select name from user_ u where c.creator_id = u.id) as creator_name,
6 (select name from category ct where c.category_id = ct.id) as category_name,
7 (select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers,
8 (select count(*) from post p where p.community_id = c.id) as number_of_posts,
9 (select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments
16 (select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed
18 cross join all_community ac
29 create view community_moderator_view as
31 (select name from user_ u where cm.user_id = u.id) as user_name,
32 (select name from community c where cm.community_id = c.id) as community_name
33 from community_moderator cm;
35 create view community_follower_view as
37 (select name from user_ u where cf.user_id = u.id) as user_name,
38 (select name from community c where cf.community_id = c.id) as community_name
39 from community_follower cf;
41 create view community_user_ban_view as
43 (select name from user_ u where cm.user_id = u.id) as user_name,
44 (select name from community c where cm.community_id = c.id) as community_name
45 from community_user_ban cm;
47 create view site_view as
49 (select name from user_ u where s.creator_id = u.id) as creator_name,
50 (select count(*) from user_) as number_of_users,
51 (select count(*) from post) as number_of_posts,
52 (select count(*) from comment) as number_of_comments