Filters allow you to only return rows that match certain conditions.
Filters can be used on select()
, update()
, and delete()
queries.
You can use two different types for applying filters:
eq("country_id", 1)
And using a class property:
City::countryId eq 1
As you can see on the property syntax: the name of the countryId
gets converted to country_id
.
By default, this is done by converting camel case to snake case, but you can customize this by changing the PropertyConversionMethod
in the Postgrest Config
If a database function returns a table response, you can also apply filters.
supabase.postgrest["cities"].select(columns = Columns.list("name", "country_id")) \{
City::name eq "The Shire"
//or
eq("name", "The Shire")
\}
supabase.postgrest["cities"].select(columns = Columns.list("name, country_id")) \{
and \{ //when both are true
City::population gt 40000
City::population lt 700000
\}
or \{ //when either one of the filters are true
City::name eq "London"
City::name eq "Berlin"
\}
\}
supabase.postgrest["users"].select \{
eq("address->postcode", 90210)
\}
supabase.postgrest["countries"].select(
columns = Columns.raw("""
name,
cities!inner (
name
)
""")
) \{
eq("cities.name", "Bali")
\}