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
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
Converts the KQLiteCursor into a cold Flow that emits the cursor whenever the underlying database tables are updated.
Eagerly maps all rows from this KQLiteCursor into a List using mapper.
Maps each emitted KQLiteCursor from the upstream Flow into a List.
Maps the first row of this KQLiteCursor into a single object of type T using mapper.
Maps each emitted KQLiteCursor from the upstream Flow into a single object of type T.
Maps the first row of this KQLiteCursor into an object of type T using mapper, or returns null if the cursor is empty.
Maps each emitted KQLiteCursor from the upstream Flow into an object of type T or null.