LayoutedColumnMapping

public struct LayoutedColumnMapping

LayoutedColumnMapping is a type that supports the RowAdapter protocol.

  • An array of (baseIndex, mappedName) pairs, where baseIndex is the index of a column in a base row, and mappedName the mapped name of that column.

    Declaration

    Swift

    public let layoutColumns: [(Int, String)]
  • Creates an LayoutedColumnMapping from an array of (baseIndex, mappedName) pairs. In each pair:

    • baseIndex is the index of a column in a base row
    • name is the mapped name of the column

    For example, the following LayoutedColumnMapping defines two columns, foo and bar, based on the base columns at indexes 1 and 2:

    LayoutedColumnMapping(layoutColumns: [(1, "foo"), (2, "bar")])
    

    Use it in your custom RowAdapter type:

    struct FooBarAdapter : RowAdapter {
        func layoutAdapter(layout: RowLayout) throws -> LayoutedRowAdapter {
            return LayoutedColumnMapping(layoutColumns: [(1, "foo"), (2, "bar")])
        }
    }
    
    // <Row foo:"foo" bar: "bar">
    try Row.fetchOne(db, "SELECT NULL, 'foo', 'bar'", adapter: FooBarAdapter())
    

    Declaration

    Swift

    public init<S: Sequence>(layoutColumns: S) where S.Iterator.Element == (Int, String)
  • Part of the LayoutedRowAdapter protocol; returns self.

    Declaration

    Swift

    public var mapping: LayoutedColumnMapping
  • Part of the LayoutedRowAdapter protocol; returns the empty dictionary.

    Declaration

    Swift

    public var scopes: [String: LayoutedRowAdapter]
  • Part of the RowLayout protocol; returns the index of the leftmost column named name, in a case-insensitive way.

    Declaration

    Swift

    public func layoutIndex(ofColumn name: String) -> Int?