RxPagingSourceDaoReturnTypeConverter


public final class RxPagingSourceDaoReturnTypeConverter


A DaoReturnTypeConverter that allows Room to return RxJava3-based RxPagingSource 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(
RxPagingSourceDaoReturnTypeConverter::class
)

Summary

Public constructors

Public methods

final @NonNull RxPagingSource<@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 an RxPagingSource.

Public constructors

RxPagingSourceDaoReturnTypeConverter

Added in 3.0.0-alpha02
public RxPagingSourceDaoReturnTypeConverter()

Public methods

convert

@DaoReturnTypeConverter(operations = [OperationType.READ])
public final @NonNull RxPagingSource<@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 an RxPagingSource.

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 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 RxPagingSource<@NonNull Integer, @NonNull T>

An RxPagingSource that emits pages of type T.