List Queries
Converting a whole list at one chunk can be memory intensive. This lazily creates models from a Cursor for you and you can operate on it s if it's a list. It a acts like a list can be used in a for-loop:
(select from MyTable::class
where ...) // some conditions
.flowQueryList(database).use { list ->
// list is just backed by an active cursor.
}
(select from MyTable::class
where ...) // some conditions
.cursorList().use { list ->
// ensure you close these when done, as they utilize active cursors :)
// can use the list like a regular List
for (model in list) {
}
list.forEach { printLn("$it") }
}Note: It's preferred within a RecyclerView to use the QueryDataSource with the Paging library, as this use can potentially lock the UI thread during heavy db usage.
Note: Ensure you close the FlowQueryList when you are done using.
FlowCursorList
The FlowCursorList is simply a wrapper around a standard Cursor, giving it the ability to cache Model, load items at specific position with conversion, and refresh its contents easily.
The FlowCursorList provides these methods:
list[index]- loads item fromCursorat specified positionrefresh()- re-queries the underlyingCursor. Use aOnCursorRefreshListenerto get callbacks when this occurs.list.all- converts it to aListof all items from theCursor, no caching used.list.count- returns count ofCursoror 0 ifCursorisnulllist.isEmpty- returns if count == 0
Flow Query List
This class is a much more powerful version of the FlowCursorList. This class acts as List and can be used almost wherever a List is used.
Last updated
Was this helpful?