So I have a supabase postgres database setup and I'm trying to use gin to setup an API for that database. I'm using nedpals/supabase-go to connect to my supabase client. I'm trying to chain multiple filters based on the request parameters like so:
func GetCardsByAdvanceSearch(supabase *supa.Client) gin.HandlerFunc {
fn := func(context *gin.Context) {
sets, isSets := context.GetQueryArray("setCode")
colors, isColors := context.GetQueryArray("color")
var results []any
err := supabase.DB.From("cards").Select("*").Execute(&results)
if(isColors) { results.In("colors", colors)}
if(isSets) { results.In("set_code", sets)}
if err != nil {
panic(err)
}
context.JSON(http.StatusOK, gin.H{
"Results": results,
})
}
return gin.HandlerFunc(fn)
}
This is based off the Supabase JS documentation that allows multiple "In" filters. But when I try to do it I keep getting errors where results.In undefined (type []any has no field or method In)
basically In
is not an applicable method on results even though it should be based on the docs.
Help please lol
Your current code is effectively doing something like this:
var results []any
results.In("colors", colors)
results
is a slice so, as the error states, "has no field or method In".
In
needs to be run against the filter before you execute the query; something like the following (untested!):
srb := supabase.DB.From("cards").Select("*")
if(isColors) {srb.In("colors", colors)}
if(isSets) {srb.In("set_code", sets)}
var results []any
err := srb.Execute(&results)