TypedRequest

public protocol TypedRequest : Request

The protocol for all types that define a way to fetch values from a database, with an attached type.

Typed requests can fetch if their associated type Fetched is fetchable (Row, value, record)

let request: ... // Some TypedRequest that fetches Person
try request.fetchCursor(db) // DatabaseCursor<Person>
try request.fetchAll(db)    // [Person]
try request.fetchOne(db)    // Person?
  • fetchCursor(_:) Extension method

    A cursor over fetched records.

    let request: ... // Some TypedRequest that fetches Person
    let persons = try request.fetchCursor(db) // DatabaseCursor<Person>
    while let person = try persons.next() {   // Person
        ...
    }
    

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

    The cursor must be iterated in a protected dispath queue.

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchCursor(_ db: Database) throws -> DatabaseCursor<Fetched>

    Parameters

    db

    A database connection.

    Return Value

    A cursor over fetched records.

  • fetchAll(_:) Extension method

    An array of fetched records.

    let request: ... // Some TypedRequest that fetches Person
    let persons = try request.fetchAll(db) // [Person]
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchAll(_ db: Database) throws -> [Fetched]

    Parameters

    db

    A database connection.

    Return Value

    An array of records.

  • fetchOne(_:) Extension method

    The first fetched record.

    let request: ... // Some TypedRequest that fetches Person
    let person = try request.fetchOne(db) // Person?
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchOne(_ db: Database) throws -> Fetched?

    Parameters

    db

    A database connection.

    Return Value

    An optional record.

  • fetchCursor(_:) Extension method

    A cursor over fetched values.

    let request: ... // Some TypedRequest that fetches String
    let strings = try request.fetchCursor(db) // DatabaseCursor<String>
    while let string = try strings.next() {   // String
        ...
    }
    

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

    The cursor must be iterated in a protected dispath queue.

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchCursor(_ db: Database) throws -> DatabaseCursor<Fetched>

    Parameters

    db

    A database connection.

    Return Value

    A cursor over fetched values.

  • fetchAll(_:) Extension method

    An array of fetched values.

    let request: ... // Some TypedRequest that fetches String
    let strings = try request.fetchAll(db) // [String]
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchAll(_ db: Database) throws -> [Fetched]

    Parameters

    db

    A database connection.

    Return Value

    An array of values.

  • fetchOne(_:) Extension method

    The first fetched value.

    The result is nil if the request returns no row, or if no value can be extracted from the first row.

    let request: ... // Some TypedRequest that fetches String
    let string = try request.fetchOne(db) // String?
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchOne(_ db: Database) throws -> Fetched?

    Parameters

    db

    A database connection.

    Return Value

    An optional value.

  • fetchCursor(_:) Extension method

    A cursor over fetched values.

    let request: ... // Some TypedRequest that fetches String
    let strings = try request.fetchCursor(db) // DatabaseCursor<String>
    while let string = try strings.next() {   // String
        ...
    }
    

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

    The cursor must be iterated in a protected dispath queue.

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchCursor(_ db: Database) throws -> DatabaseCursor<Fetched>

    Parameters

    db

    A database connection.

    Return Value

    A cursor over fetched values.

  • fetchAll(_:) Extension method

    An array of fetched values.

    let request: ... // Some TypedRequest that fetches String
    let strings = try request.fetchAll(db) // [String]
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchAll(_ db: Database) throws -> [Fetched]

    Parameters

    db

    A database connection.

    Return Value

    An array of values.

  • fetchOne(_:) Extension method

    The first fetched value.

    The result is nil if the request returns no row, or if no value can be extracted from the first row.

    let request: ... // Some TypedRequest that fetches String
    let string = try request.fetchOne(db) // String?
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchOne(_ db: Database) throws -> Fetched?

    Parameters

    db

    A database connection.

    Return Value

    An optional value.

  • fetchCursor(_:) Extension method

    A cursor over fetched optional values.

    let request: ... // Some TypedRequest that fetches Optional<String>
    let strings = try request.fetchCursor(db) // DatabaseCursor<String?>
    while let string = try strings.next() {   // String?
        ...
    }
    

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

    The cursor must be iterated in a protected dispath queue.

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchCursor(_ db: Database) throws -> DatabaseCursor<Fetched._Wrapped?>

    Parameters

    db

    A database connection.

    Return Value

    A cursor over fetched values.

  • fetchAll(_:) Extension method

    An array of fetched optional values.

    let request: ... // Some TypedRequest that fetches Optional<String>
    let strings = try request.fetchAll(db) // [String?]
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchAll(_ db: Database) throws -> [Fetched._Wrapped?]

    Parameters

    db

    A database connection.

    Return Value

    An array of values.

  • fetchCursor(_:) Extension method

    A cursor over fetched rows.

    let request: ... // Some TypedRequest that fetches Row
    let rows = try request.fetchCursor(db) // DatabaseCursor<Row>
    while let row = try rows.next() {  // Row
        let id: Int64 = row.value(atIndex: 0)
        let name: String = row.value(atIndex: 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 dispath queue.

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchCursor(_ db: Database) throws -> DatabaseCursor<Row>

    Parameters

    db

    A database connection.

    Return Value

    A cursor over fetched rows.

  • fetchAll(_:) Extension method

    An array of fetched rows.

    let request: ... // Some TypedRequest that fetches Row
    let rows = try request.fetchAll(db)
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchAll(_ db: Database) throws -> [Row]

    Parameters

    db

    A database connection.

    Return Value

    An array of fetched rows.

  • fetchOne(_:) Extension method

    The first fetched row.

    let request: ... // Some TypedRequest that fetches Row
    let row = try request.fetchOne(db)
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public func fetchOne(_ db: Database) throws -> Row?

    Parameters

    db

    A database connection.

    Return Value

    A,n optional rows.