Getting total count of records when on a view with single day
I using supabase (with Remix) for the first time to build a personal project, for tracking daily behaviors. It's pretty simple, and here is my supabase client and call for getting the daily information:
const { supabase } = await createSupabaseServerClient({request})
const { data, error } = await supabase
.from('behaviors')
.select(
.gte('created_at', stringDate)
.lt('created_at', nextDayString)
return {
data: data,
error: error
}
Success, as now I have a list of my completed behaviors for that day and the primary goal's information. But now I want to get a count for how many times each behavior has been completed this year (row count from behavior table for each behavior completed that day).
What would be best practice? The easiest solution for me would be to change this query to pull in all behaviors and on the client parse the return, but that feels like over fetching and not ideal.
const { supabase } = await createSupabaseServerClient({request})
const { data, error } = await supabase
.from('behaviors')
.select(
id, goal_id, created_at, user_id,
goals (
id, goal, value
)
).gte('created_at', stringDate)
.lt('created_at', nextDayString)
return {
data: data,
error: error
}
Success, as now I have a list of my completed behaviors for that day and the primary goal's information. But now I want to get a count for how many times each behavior has been completed this year (row count from behavior table for each behavior completed that day).
What would be best practice? The easiest solution for me would be to change this query to pull in all behaviors and on the client parse the return, but that feels like over fetching and not ideal.