From 62f5c8fc2fafb0a2e321cdf17cb019eb025a0589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 22 Feb 2018 22:18:12 +0100 Subject: [PATCH] Splitting rows: documentation WIP --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2b07d9c74..f476db77f 100644 --- a/README.md +++ b/README.md @@ -4675,10 +4675,10 @@ We merge those two adapters in a single [ScopeAdapter](#scopeadapter) that will "team": teamAdapter]) ``` -And now we can fetch, and start consuming our rows. You already know [cursor of rows](#fetching-rows): +And now we can fetch, and start consuming our rows. You already know [row cursors](#fetching-rows): ```swift - let rows = Row.fetchCursor(db, sql, adapter: adapter) + let rows = try Row.fetchCursor(db, sql, adapter: adapter) while let row = try rows.next() { ``` @@ -4721,11 +4721,11 @@ And finally, we can load the maximum score, assuming that the "maxScore" column Our introduction above has introduced important techniques. It uses [row adapters](#row-adapters) in order to split rows. It uses the `init?(leftJoinedRow:)` initializer so that missing left joined tables can be represented as a nil record. -But we have a few tasks to make it complete: +But we have a few other tasks to make it more robust: -1. It's generally easier to consume records than raw rows -2. Records not always need all columns from a table (see `TableMapping.databaseSelection` in [Columns Selected by a Request](#columns-selected-by-a-request)) -3. Building row adapters is long and error prone +1. It's generally easier to consume records than raw rows. +2. Records not always need all columns from a table (see `TableMapping.databaseSelection` in [Columns Selected by a Request](#columns-selected-by-a-request)). +3. Building row adapters is long and error prone. To address the first bullet, let's define a record that holds our player, optional team, and maximum score: @@ -4760,8 +4760,8 @@ To acknowledge that both Player and Team records may customize their selection o // Let Player and Team customize their selection: let sql = """ SELECT - \(Player.selectionSQL()), - \(Team.selectionSQL()), + \(Player.selectionSQL()), -- instead of players.* + \(Team.selectionSQL()), -- instead of teams.* MAX(rounds.score) AS maxScore FROM players LEFT JOIN teams ON ...