Kotlin: Listen to database changes

Return real-time data from your table as a Flow.

Parameters

Examples

Listen for changes in multiple rows

val flow: Flow<List<Country>> = supabase.from("countries").selectAsFlow(Country::id)
flow.collect \{
    for (country in it) \{
        println(country.name)
    \}
\}

Listen for changes in multiple rows with a filter

val flow: Flow<List<Country>> = supabase.from("countries").selectAsFlow(
    Country::id,
    filter = FilterOperation("name", FilterOperator.ILIKE, "a%")
)
flow.collect \{
    for (country in it) \{
        println(country.name)
    \}
\}

Listen for changes in a single row

val flow: Flow<Country> = supabase.from("countries").selectSingleValueAsFlow(Country::id) \{
    //You can use the same filter methods as in the `select` method, but the result is limited to a single row
    Country::id eq 1
    //or
    eq("id", 1)
\}
flow.collect \{
    println("My country is $it")
\}