# 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:

```kotlin
(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:

1. `list[index]` - loads item from `Cursor` at specified position
2. `refresh()` - re-queries the underlying `Cursor`. Use a `OnCursorRefreshListener` to get callbacks when this occurs.
3. `list.all` - converts it to a `List` of all items from the `Cursor`, no caching used.
4. `list.count` - returns count of `Cursor` or 0 if `Cursor` is `null`
5. `list.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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dbflow.gitbook.io/dbflow/usage2/advanced-usage/listbasedqueries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
