FetchRequest<Row>

Fetching Rows

  • A cursor over fetched rows.

    let request: some FetchRequest<Row> = ...
    let rows = try request.fetchCursor(db) // RowCursor
    while let row = try rows.next() {  // Row
        let id: Int64 = row[0]
        let name: String = row[1]
    }
    

    Fetched rows are reused during the cursor iteration: don’t turn a row cursor into an array with Array(rows) or rows.filter { ... } since you would not get the distinct rows you expect. Use Row.fetchAll(...) instead.

    For the same reason, make sure you make a copy whenever you extract a row for later use: row.copy().

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

    The cursor must be iterated in a protected dispatch queue.

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.
  • An array of fetched rows.

    let request: some FetchRequest<Row> = ...
    let rows = try request.fetchAll(db)
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.
  • A set of fetched rows.

    let request: some FetchRequest<Row> = ...
    let rows = try request.fetchSet(db)
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.
  • The first fetched row.

    let request: some FetchRequest<Row> = ...
    let row = try request.fetchOne(db)
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.