LiveDataDaoReturnTypeConverter


public final class LiveDataDaoReturnTypeConverter


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

Summary

Public constructors

Public methods

final @NonNull LiveData<@NonNull T>
@DaoReturnTypeConverter(operations = [OperationType.READ])
<T extends Object> convert(
    @NonNull RoomDatabase database,
    @NonNull String[] tableNames,
    @NonNull SuspendFunction0<@NonNull T> executeAndConvert
)

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-alpha03
public LiveDataDaoReturnTypeConverter()

Public methods

convert

Added in 3.0.0-alpha03
@DaoReturnTypeConverter(operations = [OperationType.READ])
public final @NonNull LiveData<@NonNull T> <T extends Object> convert(
    @NonNull RoomDatabase database,
    @NonNull String[] tableNames,
    @NonNull SuspendFunction0<@NonNull T> executeAndConvert
)

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
@NonNull RoomDatabase database

RoomDatabase instance

@NonNull String[] tableNames

List of names of the tables of the RoomDatabase

@NonNull SuspendFunction0<@NonNull T> executeAndConvert

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