'How to get total likes count of a post from supabase backend?
I have two tables one for post and one for likes. Post table stores all the post information. Likes table has 3 columns
id, post_id user_id
Now I need help to figure out how to get total number of likes of each post through supabase query. I am using react for frontend.
const { data, error } = await supabase
.from('feedback')
.select()
.order('created_on', { ascending: false });
Solution 1:[1]
Have you created a supabase client for your project?
if not follow this Doc https://github.com/supabase/supabase-js
Then import the client into the file you want to retrieve data.
you have left .select()
empty. select can be combined with modifiers
for example, you can...
const { data, error } = await supabase
.from('feedback')
.select(`post_id`)`
DOCs for reference: https://supabase.com/docs/reference/javascript/select
You may want to have your likes and post ids on the same table to save yourself from issues. Maybe add another column.
id, post_id user_id, post_likes
however your question is very broad hope this can point you in some of the right directions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | KeoooDev |