Package-level declarations

// Obtaining KQLiteCursor, it is also an Iterator. 
val cursor: KQLiteCursor = TblContact.quickSelect()

// Converting KQLiteCursor to Sequence for more features
val sequence: Sequence<KQLiteCursor> = cursor.asSequence()


// Getting row count from KQLiteCursor
val count: Int = cursor.asSequence().count()


// Mapping KQLiteCursor to list of entities, TblContact implements KQLiteAdapter
val contactList: List<Contact> = cursor.mapToList(TblContact::mapper)


// Reading single row. Throws Exception if count() != 1
val singleContact: Contact = cursor.mapToSingle(TblContact::mapper)


// Reading single item or null
val nullableContact: Contact? = cursor.mapToSingleOrNull(TblContact::mapper)


// KQLiteCursor custom mapping
val nameList: List<String> = cursor.mapToList { it[TblContact.firstName] }


// Converting KQLiteCursor to Flow. It does not observe table changes.
val flow: Flow<KQLiteCursor> = cursor.asFlow()


// Mapping Flow to other types
val nameFlow: Flow<String> = cursor.asFlow().map { it[TblContact.firstName] }


// Converting KQLiteCursor to CallbackFlow. Observe table changes INSERT, UPDATE and DELETE.
val callbackFlow: Flow<KQLiteCursor> = cursor.asCallbackFlow()


// Mapping Flow to List of observable entities.
val contactsFlow: Flow<List<Contact>> =
cursor.asCallbackFlow().mapToList(mapper = TblContact::mapper)


// Custom dispatcher, default is IO, if not given.
val dispatcher: Flow<List<Contact>> =
cursor.asCallbackFlow().mapToList(Dispatchers.Main, TblContact::mapper)


// Observable Flow of nullable item.
val singleFlow: Flow<Contact?> =
cursor.asCallbackFlow().mapToSingleOrNull(mapper = TblContact::mapper)

Types

Link copied to clipboard

Provides a read-only, forward-only, type-safe cursor as Iterator over the result set of underlying database cursor. Helpful to use with Kotlin forEach.

Functions

Link copied to clipboard

Converts the KQLiteCursor into a cold Flow that emits the cursor whenever the underlying database tables are updated.

Link copied to clipboard
fun <T> KQLiteCursor.mapToList(mapper: (KQLiteCursor) -> T): List<T>

Eagerly maps all rows from this KQLiteCursor into a List using mapper.

fun <T> Flow<KQLiteCursor>.mapToList(dispatcher: CoroutineDispatcher? = null, mapper: (KQLiteCursor) -> T): Flow<List<T>>

Maps each emitted KQLiteCursor from the upstream Flow into a List.

Link copied to clipboard
fun <T> KQLiteCursor.mapToSingle(mapper: (KQLiteCursor) -> T): T

Maps the first row of this KQLiteCursor into a single object of type T using mapper.

fun <T> Flow<KQLiteCursor>.mapToSingle(dispatcher: CoroutineDispatcher? = null, mapper: (KQLiteCursor) -> T): Flow<T>

Maps each emitted KQLiteCursor from the upstream Flow into a single object of type T.

Link copied to clipboard

Maps the first row of this KQLiteCursor into an object of type T using mapper, or returns null if the cursor is empty.

fun <T> Flow<KQLiteCursor>.mapToSingleOrNull(dispatcher: CoroutineDispatcher? = null, mapper: (KQLiteCursor) -> T): Flow<T?>

Maps each emitted KQLiteCursor from the upstream Flow into an object of type T or null.