RxPagingSourceDaoReturnTypeConverter


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 functions

RxPagingSource<Int, T>
@DaoReturnTypeConverter(operations = [OperationType.READ])
<T : Any> convert(
    database: RoomDatabase,
    tableNames: Array<String>,
    roomRawQuery: RoomRawQuery,
    executeAndConvert: suspend (RoomRawQuery) -> List<T>
)

Converts a Room query into an RxPagingSource.

Public constructors

RxPagingSourceDaoReturnTypeConverter

Added in 3.0.0-alpha03
RxPagingSourceDaoReturnTypeConverter()

Public functions

convert

@DaoReturnTypeConverter(operations = [OperationType.READ])
fun <T : Any> convert(
    database: RoomDatabase,
    tableNames: Array<String>,
    roomRawQuery: RoomRawQuery,
    executeAndConvert: suspend (RoomRawQuery) -> List<T>
): RxPagingSource<Int, T>

Converts a Room query into an RxPagingSource.

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

roomRawQuery: RoomRawQuery

The initial RoomRawQuery to be executed.

executeAndConvert: suspend (RoomRawQuery) -> List<T>

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
RxPagingSource<Int, T>

An RxPagingSource that emits pages of type T.