Row

public struct Row
extension Row: CustomStringConvertible
extension Row: Collection

A result row containing one or more columns with type-safe value access.

Creation

A row is not created directly but is obtained from a Statement.

try statement.execute() { row in
    // Do something with `row`
}

Column Value Access

The database-native column value is expressed by DatabaseValue, however custom type conversion is possible when a type implements either the ColumnConvertible or DatabaseSerializable protocol.

The value of columns is accessed by the value(at:) or value(named:) methods.

let value = try row.value(at: 0)
let uuid: UUID = try row.value(named: "session_uuid")

It is also possible to iterate over column values:

for row in statement {
    for value in row {
        // Do something with `value`
    }

}

This allows for simple result row processing at the expense of error handling.

  • The statement owning this row.

    Declaration

    Swift

    public let statement: Statement
  • The number of columns in the row.

    Declaration

    Swift

    public let columnCount: Int
  • Returns the name of the column at index.

    This is a shortcut for statement.name(ofColumn: index).

    Note

    Column indexes are 0-based. The leftmost column in a result row has index 0.

    Requires

    index >= 0

    Requires

    index < self.columnCount

    Throws

    An error if index is out of bounds

    Declaration

    Swift

    public func name(ofColumn index: Int) throws -> String

    Parameters

    index

    The index of the desired column

    Return Value

    The name of the column

  • Returns the index of the column with name name.

    This is a shortcut for statement.index(ofColumn: name).

    Throws

    An error if the column doesn’t exist

    Declaration

    Swift

    public func index(ofColumn name: String) throws -> Int

    Parameters

    name

    The name of the desired column

    Return Value

    The index of the column

  • Returns the value of the column at index.

    Note

    Column indexes are 0-based. The leftmost column in a row has index 0.

    Requires

    index >= 0

    Requires

    index < self.columnCount

    Throws

    An error if index is out of bounds or the column contains an illegal value

    Declaration

    Swift

    public func value<T>(at index: Int) throws -> T? where T : ColumnConvertible

    Parameters

    index

    The index of the desired column

    Return Value

    The column’s value or nil if null

  • Returns the value of the column at index.

    Note

    Column indexes are 0-based. The leftmost column in a row has index 0.

    Requires

    index >= 0

    Requires

    index < self.columnCount

    Throws

    An error if index is out of bounds or the column contains a null or illegal value

    Declaration

    Swift

    public func value<T>(at index: Int) throws -> T where T : ColumnConvertible

    Parameters

    index

    The index of the desired column

    Return Value

    The column’s value

  • Returns the value of the column with name name.

    Throws

    An error if the column doesn’t exist or contains an illegal value

    Declaration

    Swift

    public func value<T>(named name: String) throws -> T? where T : ColumnConvertible

    Parameters

    name

    The name of the desired column

    Return Value

    The column’s value or nil if null

  • Returns the value of the column with name name.

    Throws

    An error if the column doesn’t exist or contains a null or illegal value

    Declaration

    Swift

    public func value<T>(named name: String) throws -> T where T : ColumnConvertible

    Parameters

    name

    The name of the desired column

    Return Value

    The column’s value

  • Undocumented

    Declaration

    Swift

    public subscript<T>(at index: Int) -> T? where T : ColumnConvertible { get }
  • Undocumented

    Declaration

    Swift

    public subscript<T>(named name: String) -> T? where T : ColumnConvertible { get }
  • Returns the value of the leftmost column.

    This is a shortcut for value(at: 0).

    Throws

    An error if there are no columns or the column contains a null or illegal value

    Declaration

    Swift

    public func leftmostValue<T>() throws -> T where T : ColumnConvertible

    Return Value

    The column’s value

  • Returns the value of the column at index.

    Note

    Column indexes are 0-based. The leftmost column in a row has index 0.

    Requires

    index >= 0

    Requires

    index < self.columnCount

    Throws

    An error if the column contains an illegal value

    Declaration

    Swift

    public func value<T>(at index: Int) throws -> T where T : DatabaseSerializable

    Parameters

    index

    The index of the desired column

    Return Value

    The column’s value

  • Returns the value of the column with name name.

    Throws

    An error if the column wasn’t found or contains an illegal value

    Declaration

    Swift

    public func value<T>(named name: String) throws -> T where T : DatabaseSerializable

    Parameters

    name

    The name of the desired column

    Return Value

    The column’s value

  • Returns the value of the leftmost column.

    This is a shortcut for value(at: 0).

    Throws

    An error if there are no columns or the column contains an illegal value

    Declaration

    Swift

    public func leftmostValue<T>() throws -> T where T : DatabaseSerializable

    Return Value

    The first column’s value or nil if null

  • Returns the value of the column at index.

    Note

    Column indexes are 0-based. The leftmost column in a row has index 0.

    Requires

    index >= 0

    Requires

    index < self.columnCount

    Throws

    An error if index is out of bounds

    Declaration

    Swift

    public func value(at index: Int) throws -> DatabaseValue

    Parameters

    index

    The index of the desired column

    Return Value

    The column’s value

  • Returns the value of the column with name name.

    Throws

    An error if the column doesn’t exist

    Declaration

    Swift

    public func value(named name: String) throws -> DatabaseValue

    Parameters

    name

    The name of the desired column

    Return Value

    The column’s value

  • Returns the value of the leftmost column.

    This is a shortcut for value(at: 0).

    Throws

    An error if there are no columns

    Declaration

    Swift

    public func leftmostValue() throws -> DatabaseValue

    Return Value

    The column’s value

  • Returns a dictionary of the row’s values keyed by column name.

    Declaration

    Swift

    public func values() -> [String : DatabaseValue]

    Return Value

    A dictionary of the row’s values

  • A description of the type and value of self.

    Declaration

    Swift

    public var description: String { get }
  • Returns the value of the column with name name.

    Declaration

    Swift

    public subscript(name: String) -> DatabaseValue? { get }

    Parameters

    name

    The name of the desired column

    Return Value

    The column’s value or nil if the column doesn’t exist

  • Declaration

    Swift

    public var startIndex: Int { get }
  • Declaration

    Swift

    public var endIndex: Int { get }
  • Declaration

    Swift

    public subscript(position: Int) -> DatabaseValue { get }
  • Declaration

    Swift

    public func index(after i: Int) -> Int