Update documentation for new Row description format

This commit is contained in:
Gwendal Roué committed 2018-04-11 15:49:16 +02:00
1 parent fa68b62be1
commit 26912e746b
5 files changed
+25 -25

No files matched your search

+1 -1
View File
@@ -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:"...">
// 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]
+1 -1
View File
@@ -804,7 +804,7 @@ extension Row {
///
/// let row: Row = ["foo": 1, "foo": "bar", "baz": nil]
/// print(row)
/// // Prints <Row foo:1 foo:"bar" baz:NULL>
/// // 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) }))
}
+6 -6
View File
@@ -77,7 +77,7 @@ public struct LayoutedColumnMapping {
/// }
/// }
///
/// // <Row foo:"foo" bar: "bar">
/// // [foo:"foo" bar: "bar"]
/// try Row.fetchOne(db, "SELECT NULL, 'foo', 'bar'", adapter: FooBarAdapter())
public init<S: Sequence>(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"
///
/// // <Row baz:3>
/// // [baz:3]
/// try Row.fetchOne(db, sql, adapter: adapter)
public protocol RowAdapter {
@@ -223,7 +223,7 @@ public protocol RowAdapter {
/// }
/// }
///
/// // <Row foo:1>
/// // [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"
///
/// // <Row foo:"bar">
/// // [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"
///
/// // <Row baz:3>
/// // [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"
///
/// // <Row bar:2 baz: 3>
/// // [bar:2 baz: 3]
/// try Row.fetchOne(db, sql, adapter: adapter)
public struct RangeRowAdapter : RowAdapter {
/// The range
+1 -1
View File
@@ -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 <Row two:2 foo:"foo" one:1 foo2:"foo" bar:"bar">
/// // 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] = [:]
+16 -16
View File
@@ -1634,14 +1634,14 @@ try db.create(table: "players") { t in
t.column("name", .text)
}
// <Row type:"table" name:"players" tbl_name:"players" rootpage:2
// sql:"CREATE TABLE players(id INTEGER PRIMARY KEY, 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)
}
// <Row cid:0 name:"id" type:"INTEGER" notnull:0 dflt_value:NULL pk:1>
// <Row cid:1 name:"name" type:"TEXT" notnull:0 dflt_value:NULL pk:0>
// [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
// <Row newName:"Hello">
// [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
// <Row b:1 c:2>
// [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
// <Row b:1>
// [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 a:0 b:1 c:2 d:3>
row.scoped(on: "left") // <Row a:0 b:1>
row.scoped(on: "right") // <Row c:2 d:3>
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") // <Row a:0>
leftRow.scoped(on: "right") // <Row b:1>
leftRow.scoped(on: "left") // [a:0]
leftRow.scoped(on: "right") // [b:1]
let rightRow = row.scoped(on: "right")!
rightRow.scoped(on: "left") // <Row c:2>
rightRow.scoped(on: "right") // <Row d:3>
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 a:0 b:1>
row.scoped(on: "remainder") // <Row c:2 d:3>
row // [a:0 b:1]
row.scoped(on: "remainder") // [c:2 d:3]
```