PagingSourceDaoReturnTypeConverter


public final class PagingSourceDaoReturnTypeConverter


A DaoReturnTypeConverter that allows Room to return PagingSource types from @Dao functions.

You can register this converter via annotating a androidx.room3.Database or androidx.room3.Dao using the annotation androidx.room3.DaoReturnTypeConverters:

@DaoReturnTypeConverters(
PagingSourceDaoReturnTypeConverter::class
)

Summary

Public constructors

Public methods

final @NonNull PagingSource<@NonNull Integer, @NonNull T>
@DaoReturnTypeConverter(operations = [OperationType.READ])
<T extends Object> convert(
    @NonNull RoomDatabase database,
    @NonNull String[] tableNames,
    @NonNull RoomRawQuery roomRawQuery,
    @NonNull SuspendFunction1<@NonNull RoomRawQuery, @NonNull List<@NonNull T>> executeAndConvert
)

Converts a Room query into a PagingSource.

Public constructors

PagingSourceDaoReturnTypeConverter

Added in 3.0.0-alpha02
public PagingSourceDaoReturnTypeConverter()

Public methods

convert

@DaoReturnTypeConverter(operations = [OperationType.READ])
public final @NonNull PagingSource<@NonNull Integer, @NonNull T> <T extends Object> convert(
    @NonNull RoomDatabase database,
    @NonNull String[] tableNames,
    @NonNull RoomRawQuery roomRawQuery,
    @NonNull SuspendFunction1<@NonNull RoomRawQuery, @NonNull List<@NonNull T>> executeAndConvert
)

Converts a Room query into a PagingSource.

This converter can be used for both OperationType.READ and OperationType.WRITE. Note that Room shortcut methods (@Insert, @Update, @Delete) are always treated as OperationType.WRITE.

Parameters
@NonNull RoomDatabase database

RoomDatabase instance.

@NonNull String[] tableNames

List of names of the tables of the RoomDatabase to observe for invalidation.

@NonNull RoomRawQuery roomRawQuery

The initial RoomRawQuery to be executed.

@NonNull SuspendFunction1<@NonNull RoomRawQuery, @NonNull List<@NonNull T>> executeAndConvert

A suspend lambda function that invokes the part of the generated code that executes the query. This function takes a RoomRawQuery (modified for limit/offset) and returns a List of T. This ensures that each page load retrieves the expected list of items.

Returns
@NonNull PagingSource<@NonNull Integer, @NonNull T>

A PagingSource that emits pages of type T.