LiveDataDaoReturnTypeConverter


class LiveDataDaoReturnTypeConverter


A DaoReturnTypeConverter container that allows Room to return LiveData from androidx.room3.Dao functions.

Summary

Public constructors

Public functions

LiveData<T>
@DaoReturnTypeConverter(operations = [OperationType.READ])
<T : Any?> convert(
    database: RoomDatabase,
    tableNames: Array<String>,
    executeAndConvert: suspend () -> T
)

This convert function will be called from Room generated code to convert a Room query result to the return type of this function.

Public constructors

LiveDataDaoReturnTypeConverter

Added in 3.0.0-alpha04
LiveDataDaoReturnTypeConverter()

Public functions

convert

Added in 3.0.0-alpha04
@DaoReturnTypeConverter(operations = [OperationType.READ])
fun <T : Any?> convert(
    database: RoomDatabase,
    tableNames: Array<String>,
    executeAndConvert: suspend () -> T
): LiveData<T>

This convert function will be called from Room generated code to convert a Room query result to the return type of this function.

The returned LiveData is backed by a kotlinx.coroutines.flow.Flow and created via the asLiveData API on Room's kotlinx.coroutines.flow.Flow returned by the androidx.room3.InvalidationTracker.createFlow. It inherits the default timeout behavior (5 seconds) where the upstream Flow is cancelled if the LiveData becomes inactive.

This converter can be only be used for OperationType.READ.

Parameters
database: RoomDatabase

RoomDatabase instance

tableNames: Array<String>

List of names of the tables of the RoomDatabase

executeAndConvert: suspend () -> T

A suspend lambda function that invokes the part of the generated code that executes the query.