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 >= 0Requires
index < self.columnCountThrows
An error if
indexis out of boundsDeclaration
Swift
public func name(ofColumn index: Int) throws -> StringParameters
indexThe 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 -> IntParameters
nameThe 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 >= 0Requires
index < self.columnCountThrows
An error if
indexis out of bounds or the column contains an illegal valueDeclaration
Swift
public func value<T>(at index: Int) throws -> T? where T : ColumnConvertibleParameters
indexThe index of the desired column
Return Value
The column’s value or
nilif 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 >= 0Requires
index < self.columnCountThrows
An error if
indexis out of bounds or the column contains a null or illegal valueDeclaration
Swift
public func value<T>(at index: Int) throws -> T where T : ColumnConvertibleParameters
indexThe 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 : ColumnConvertibleParameters
nameThe name of the desired column
Return Value
The column’s value or
nilif 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 : ColumnConvertibleParameters
nameThe 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 : ColumnConvertibleReturn 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 >= 0Requires
index < self.columnCountThrows
An error if the column contains an illegal value
Declaration
Swift
public func value<T>(at index: Int) throws -> T where T : DatabaseSerializableParameters
indexThe 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 : DatabaseSerializableParameters
nameThe 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 : DatabaseSerializableReturn Value
The first column’s value or
nilif 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 >= 0Requires
index < self.columnCountThrows
An error if
indexis out of boundsDeclaration
Swift
public func value(at index: Int) throws -> DatabaseValueParameters
indexThe 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 -> DatabaseValueParameters
nameThe 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 -> DatabaseValueReturn 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
nameThe name of the desired column
Return Value
The column’s value or
nilif 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
View on GitHub
Row Structure Reference