Instance Methodgrdb 7.1.0GRDB

fetchCursor(_:)

Returns a cursor over fetched values.

DatabaseValueConvertible.swift:730
func fetchCursor(_ db: Database) throws -> DatabaseValueCursor<RowDecoder>

Parameters

db

A database connection.

Returns

A DatabaseValueCursor over fetched values.

Throws

A DatabaseError whenever an SQLite error occurs.

For example:

try dbQueue.read { db in
    let lastName = "O'Reilly"

    // Query interface request
    let request = Player
        .filter(Column("lastName") == lastName)
        .select(Column("score"), as: Int.self)

    // SQL request
    let request: SQLRequest<Int> = """
        SELECT score FROM player WHERE lastName = \(lastName)
        """

    let scores = try request.fetchCursor(db)
    while let score = try scores.next() {
        print(score)
    }
}

Values are decoded from the leftmost column.

The returned cursor is valid only during the remaining execution of the database access. Do not store or return the cursor for later use.

If the database is modified during the cursor iteration, the remaining elements are undefined.