ScopesView

public struct ScopesView : Collection

A view of the scopes defined by row adapters. It is a collection of tuples made of a scope name and a scoped row, which behaves like a dictionary.

For example:

// Define a tree of nested scopes
let adapter = ScopeAdapter([
    "foo": RangeRowAdapter(0..<1),
    "bar": RangeRowAdapter(1..<2).addingScopes([
        "baz" : RangeRowAdapter(2..<3)])])

// Fetch
let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz"
let row = try Row.fetchOne(db, sql: sql, adapter: adapter)!

row.scopes.count  // 2
row.scopes.names  // ["foo", "bar"]

row.scopes["foo"] // [foo:1]
row.scopes["bar"] // [bar:2]
row.scopes["baz"] // nil
  • Declaration

    Swift

    public typealias Index = Dictionary<String, LayoutedRowAdapter>.Index
  • The scopes defined on this row.

    Declaration

    Swift

    public var names: Dictionary<String, LayoutedRowAdapter>.Keys { get }
  • Returns the row associated with the given scope, or nil if the scope is not defined.

    Declaration

    Swift

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