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["characters"].select(columns = Columns.list("name, book_id")) \{
and \{ //when both are true
Character::age gt 10
Character::age lt 150
\}
or \{ //when either one of the filters are true
Character::name eq "Harry"
Character::name eq "Dumbledore"
\}
\}
supabase.postgrest["users"].select \{
eq("address->postcode", 90210)
\}
supabase.postgrest["orchestral_sections"].select(
columns = Columns.raw("""
name,
instruments!inner (
name
)
""")
) \{
eq("instruments.name", "flute")
\}