Optional

enum Optional<Wrapped> : ExpressibleByNilLiteral
  • Returns a cursor over optional values fetched from a prepared statement.

    let statement = try db.makeSelectStatement("SELECT name FROM ...")
    let names = try Optional<String>.fetchCursor(statement) // DatabaseCursor<String?>
    while let name = try names.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 static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseCursor<Wrapped?>

    Parameters

    statement

    The statement to run.

    arguments

    Optional statement arguments.

    adapter

    Optional RowAdapter

    Return Value

    A cursor over fetched optional values.

  • Returns an array of optional values fetched from a prepared statement.

    let statement = try db.makeSelectStatement("SELECT name FROM ...")
    let names = try Optional<String>.fetchAll(statement)  // [String?]
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?]

    Parameters

    statement

    The statement to run.

    arguments

    Optional statement arguments.

    adapter

    Optional RowAdapter

    Return Value

    An array of optional values.

  • Returns a cursor over optional values fetched from a fetch request.

    let nameColumn = Column("name")
    let request = Person.select(nameColumn)
    let names = try Optional<String>.fetchCursor(db, request) // DatabaseCursor<String?>
    while let name = try names.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 static func fetchCursor(_ db: Database, _ request: Request) throws -> DatabaseCursor<Wrapped?>

    Parameters

    db

    A database connection.

    requet

    A fetch request.

    Return Value

    A cursor over fetched optional values.

  • Returns an array of optional values fetched from a fetch request.

    let nameColumn = Column("name")
    let request = Person.select(nameColumn)
    let names = try Optional<String>.fetchAll(db, request) // [String?]
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public static func fetchAll(_ db: Database, _ request: Request) throws -> [Wrapped?]

    Parameters

    db

    A database connection.

  • Returns a cursor over optional values fetched from an SQL query.

    let names = try Optional<String>.fetchCursor(db, "SELECT name FROM ...") // DatabaseCursor<String?>
    while let name = try names.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 static func fetchCursor(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseCursor<Wrapped?>

    Parameters

    db

    A database connection.

    sql

    An SQL query.

    arguments

    Optional statement arguments.

    adapter

    Optional RowAdapter

    Return Value

    A cursor over fetched optional values.

  • Returns an array of optional values fetched from an SQL query.

    let names = try String.fetchAll(db, "SELECT name FROM ...") // [String?]
    

    Throws

    A DatabaseError is thrown whenever an SQLite error occurs.

    Declaration

    Swift

    public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?]

    Parameters

    db

    A database connection.

    sql

    An SQL query.

    parameter arguments

    Optional statement arguments.

    adapter

    Optional RowAdapter

    Return Value

    An array of optional values.