diff --git a/GRDB/Core/Database+Schema.swift b/GRDB/Core/Database+Schema.swift index 4c053acb5..7ac80ece1 100644 --- a/GRDB/Core/Database+Schema.swift +++ b/GRDB/Core/Database+Schema.swift @@ -193,7 +193,7 @@ extension Database { var rawForeignKeys: [(destinationTable: String, mapping: [(origin: String, destination: String?, seq: Int)])] = [] var previousId: Int? = nil for row in try Row.fetchAll(self, "PRAGMA foreign_key_list(\(tableName.quotedDatabaseIdentifier))") { - // row = + // row = [id:0 seq:0 table:"parents" from:"parentId" to:"id" on_update:"..." on_delete:"..." match:"..."] let id: Int = row[0] let seq: Int = row[1] let table: String = row[2] diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 5ef3922de..77abae6bc 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -804,7 +804,7 @@ extension Row { /// /// let row: Row = ["foo": 1, "foo": "bar", "baz": nil] /// print(row) - /// // Prints + /// // Prints [foo:1 foo:"bar" baz:NULL] public convenience init(dictionaryLiteral elements: (String, DatabaseValueConvertible?)...) { self.init(impl: ArrayRowImpl(columns: elements.map { ($0, $1?.databaseValue ?? .null) })) } diff --git a/GRDB/Core/RowAdapter.swift b/GRDB/Core/RowAdapter.swift index 68f9bedfe..014d97f88 100644 --- a/GRDB/Core/RowAdapter.swift +++ b/GRDB/Core/RowAdapter.swift @@ -77,7 +77,7 @@ public struct LayoutedColumnMapping { /// } /// } /// - /// // + /// // [foo:"foo" bar: "bar"] /// try Row.fetchOne(db, "SELECT NULL, 'foo', 'bar'", adapter: FooBarAdapter()) public init(layoutColumns: S) where S.Iterator.Element == (Int, String) { self.layoutColumns = Array(layoutColumns) @@ -200,7 +200,7 @@ extension SelectStatement : RowLayout { /// let adapter = SuffixRowAdapter(fromIndex: 2) /// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz" /// -/// // +/// // [baz:3] /// try Row.fetchOne(db, sql, adapter: adapter) public protocol RowAdapter { @@ -223,7 +223,7 @@ public protocol RowAdapter { /// } /// } /// - /// // + /// // [foo:1] /// try Row.fetchOne(db, "SELECT 1, 2, 3", adapter: FirstColumnAdapter()) func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter } @@ -264,7 +264,7 @@ public struct EmptyRowAdapter: RowAdapter { /// let adapter = ColumnMapping(["foo": "bar"]) /// let sql = "SELECT 'foo' AS foo, 'bar' AS bar, 'baz' AS baz" /// -/// // +/// // [foo:"bar"] /// try Row.fetchOne(db, sql, adapter: adapter) public struct ColumnMapping : RowAdapter { /// A dictionary from mapped column names to column names in a base row. @@ -298,7 +298,7 @@ public struct ColumnMapping : RowAdapter { /// let adapter = SuffixRowAdapter(fromIndex: 2) /// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz" /// -/// // +/// // [baz:3] /// try Row.fetchOne(db, sql, adapter: adapter) public struct SuffixRowAdapter : RowAdapter { /// The suffix index @@ -325,7 +325,7 @@ public struct SuffixRowAdapter : RowAdapter { /// let adapter = RangeRowAdapter(1..<3) /// let sql = "SELECT 1 AS foo, 2 AS bar, 3 AS baz, 4 as qux" /// -/// // +/// // [bar:2 baz: 3] /// try Row.fetchOne(db, sql, adapter: adapter) public struct RangeRowAdapter : RowAdapter { /// The range diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift index b5bfa0dc1..c84ac6e1e 100644 --- a/GRDB/Core/Statement.swift +++ b/GRDB/Core/Statement.swift @@ -584,7 +584,7 @@ extension UpdateStatement: AuthorizedStatement { } /// let sql = "SELECT ?2 AS two, :foo AS foo, ?1 AS one, :foo AS foo2, :bar AS bar" /// let row = try Row.fetchOne(db, sql, arguments: [1, 2, "bar"] + ["foo": "foo"])! /// print(row) -/// // Prints +/// // Prints [two:2 foo:"foo" one:1 foo2:"foo" bar:"bar"] public struct StatementArguments: CustomStringConvertible, Equatable, ExpressibleByArrayLiteral, ExpressibleByDictionaryLiteral { var values: [DatabaseValue] = [] var namedValues: [String: DatabaseValue] = [:] diff --git a/README.md b/README.md index f4541e5c9..c7db629b2 100644 --- a/README.md +++ b/README.md @@ -1634,14 +1634,14 @@ try db.create(table: "players") { t in t.column("name", .text) } -// +// [type:"table" name:"players" tbl_name:"players" rootpage:2 +// sql:"CREATE TABLE players(id INTEGER PRIMARY KEY, name TEXT)"] for row in try Row.fetchAll(db, "SELECT * FROM sqlite_master") { print(row) } -// -// +// [cid:0 name:"id" type:"INTEGER" notnull:0 dflt_value:NULL pk:1] +// [cid:1 name:"name" type:"TEXT" notnull:0 dflt_value:NULL pk:0] for row in try Row.fetchAll(db, "PRAGMA table_info('players')") { print(row) } @@ -1687,7 +1687,7 @@ To see how row adapters can be used, see [Joined Queries Support](#joined-querie ColumnMapping renames columns. Build one with a dictionary whose keys are adapted column names, and values the column names in the raw row: ```swift -// +// [newName:"Hello"] let adapter = ColumnMapping(["newName": "oldName"]) let row = try Row.fetchOne(db, "SELECT 'Hello' AS oldName", adapter: adapter)! ``` @@ -1697,7 +1697,7 @@ let row = try Row.fetchOne(db, "SELECT 'Hello' AS oldName", adapter: adapter)! `SuffixRowAdapter` hides the first columns in a row: ```swift -// +// [b:1 c:2] let adapter = SuffixRowAdapter(fromIndex: 1) let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)! ``` @@ -1707,7 +1707,7 @@ let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter `RangeRowAdapter` only exposes a range of columns. ```swift -// +// [b:1] let adapter = RangeRowAdapter(1..<2) let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c", adapter: adapter)! ``` @@ -1739,9 +1739,9 @@ let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: ScopeAdapter does not change the columns and values of the fetched row. Instead, it defines *scopes*, which you access with the `Row.scoped(on:)` method. This method returns an optional Row, which is nil if the scope is missing. ```swift -row // -row.scoped(on: "left") // -row.scoped(on: "right") // +row // [a:0 b:1 c:2 d:3] +row.scoped(on: "left") // [a:0 b:1] +row.scoped(on: "right") // [c:2 d:3] row.scoped(on: "missing") // nil ``` @@ -1759,12 +1759,12 @@ let adapter = ScopeAdapter([ let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)! let leftRow = row.scoped(on: "left")! -leftRow.scoped(on: "left") // -leftRow.scoped(on: "right") // +leftRow.scoped(on: "left") // [a:0] +leftRow.scoped(on: "right") // [b:1] let rightRow = row.scoped(on: "right")! -rightRow.scoped(on: "left") // -rightRow.scoped(on: "right") // +rightRow.scoped(on: "left") // [c:2] +rightRow.scoped(on: "right") // [d:3] ``` Any adapter can be extended with scopes: @@ -1775,8 +1775,8 @@ let adapter = ScopeAdapter(base: baseAdapter, scopes: [ "remainder": SuffixRowAdapter(fromIndex: 2)]) let row = try Row.fetchOne(db, "SELECT 0 AS a, 1 AS b, 2 AS c, 3 AS d", adapter: adapter)! -row // -row.scoped(on: "remainder") // +row // [a:0 b:1] +row.scoped(on: "remainder") // [c:2 d:3] ```