Skip to content

Commit

Permalink
feat(hasura): add total creator subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Aug 4, 2023
1 parent 9b10a58 commit 81ba787
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
10 changes: 10 additions & 0 deletions hasura/metadata/databases/punkga-pg/tables/public_creators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ array_relationships:
table:
name: manga_creator
schema: public
computed_fields:
- name: total_subscribers
definition:
function:
name: total_creator_subscribers
schema: public
select_permissions:
- role: anonymous
permission:
Expand All @@ -22,6 +28,8 @@ select_permissions:
- name
- created_at
- updated_at
computed_fields:
- total_subscribers
filter: {}
allow_aggregations: true
- role: user
Expand All @@ -36,6 +44,8 @@ select_permissions:
- name
- created_at
- updated_at
computed_fields:
- total_subscribers
filter: {}
limit: 20
allow_aggregations: true
37 changes: 19 additions & 18 deletions hasura/metadata/query_collections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -346,24 +346,6 @@
signup_methods
}
}
- name: Admin - Query creators
query: |
query QueryCreators {
creators(order_by: {created_at:desc}) {
id
name
manga_creators_aggregate {
aggregate {
count
}
}
subcribers
created_at
socials
isActive
bio
}
}
- name: Admin - Get chapter detail
query: |
query GetChapterDetail ($manga_id: Int = 18, $chapter_number: Int = 1) {
Expand Down Expand Up @@ -844,3 +826,22 @@
}
}
}
- name: Admin - Query creators
query: |
query QueryCreators {
creators(order_by: {created_at:desc}) {
id
name
total_subscribers
manga_creators_aggregate {
aggregate {
count
}
}
subcribers
created_at
socials
isActive
bio
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- CREATE OR REPLACE FUNCTION total_creator_subscribers(creator_row creators) RETURNS
-- int
-- AS $$
-- SELECT COUNT(1) as total_subscribers FROM public.subscribers
-- INNER JOIN manga_creator mc on subscribers.manga_id = mc.manga_id
-- WHERE mc.creator_id = creator_row.id
-- $$ LANGUAGE sql STABLE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE OR REPLACE FUNCTION total_creator_subscribers(creator_row creators) RETURNS
int
AS $$
SELECT COUNT(1) as total_subscribers FROM public.subscribers
INNER JOIN manga_creator mc on subscribers.manga_id = mc.manga_id
WHERE mc.creator_id = creator_row.id
$$ LANGUAGE sql STABLE;

0 comments on commit 81ba787

Please sign in to comment.