Changes
Realtime
- Add an option (
Realtime.Config#disconnectOnNoSubscriptions) to automatically disconnect from the websocket, once there is no channel left, which defaults to true. (in #416 by @jan-tennert) - Provide a new way to listen to Realtime data (built on top of the existing ones) (in #386 by @jan-tennert):
Note: For both methods, the flows automatically emit the initial data and then listen for events using the existing methods.
Listen for changes in all messages (handles inserts, updates and deletes automatically and emits the updated list)
val messageFlow: Flow<List<Message>> = channel.postgresListDataFlow<Message>( //provide your serializable type (in this case Message)
table = "messages",
filter = FilterOperation("id", FilterOperator.IN, listOf(1, 2, 3, 4)), //optional filter
primaryKey = Message::id //provide the primary key for caching
)Listen for changes on a single value
val singleMessageFlow: Flow<Message> = channel.postgresSingleDataFlow<Message>( //Automatically emits the updated message and closes on delete
table = "messages",
primaryKey = Message::id
) { //this is the same filter builder the Postgrest plugin uses, so you can use everything:
Message::id eq 2
or {
Message::creatorId isIn listOf("1", "2", "3")
Message::content like "%test%"
}
}Listen to presence changes (joins & leaves are handled automatically)
val presenceFlow: Flow<List<User>> = channel.presenceDataFlow<User>()- Add a new method for adding a filter to postgres changes:
supabase.channel("channel").postgresChangeFlow<PostgresAction>("public") {
//Still only one filter supported
filter("id", FilterOperator.EQ, 2)
//Note that some values get converted to strings e.g. the List<Int> to (1,2,3)
filter("id", FilterOperator.IN, listOf(1, 2, 3, 4))
}New methods:
RealtimeChannel#postgresSingleDataFlowRealtimeChannel#postgresListDataFlowRealtimeChannel#presenceDataFlowRealtimeChannelBuilder#filter