From 33174fce8e05b447f9ea42a71ab694f536fd2af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Fri, 12 Mar 2021 14:00:31 +0100 Subject: [PATCH] Documentation --- CHANGELOG.md | 2 +- README.md | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f6330788..27aacfc85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,7 +80,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: - **New**: [#936](https://github.com/groue/GRDB.swift/pull/936): Complete Associations and the DerivableRequest Protocol -- **New**: Database cursors can feed more standard Swift collections: `Array(cursor, minimumCapacity: ...)`, `Dictionary(uniqueKeysWithValues: cursor)`, etc` (see [Cursors](README.md#cursors)). +- **New**: Database cursors can feed more standard Swift collections: `Array(cursor, minimumCapacity: ...)`, `Dictionary(uniqueKeysWithValues: cursor)`, etc (see [Cursors](README.md#cursors)). - **Documentation update**: The [Associations Guide](Documentation/AssociationsBasics.md) has gained a new [Further Refinements to Associations](Documentation/AssociationsBasics.md#further-refinements-to-associations) chapter which shows the new association methods brought by [#936](https://github.com/groue/GRDB.swift/pull/936). diff --git a/README.md b/README.md index 90b14381f..a5807ae0e 100644 --- a/README.md +++ b/README.md @@ -815,9 +815,11 @@ try dbQueue.read { db in - **Cursors are granted with direct access to SQLite,** unlike arrays and sets that have to take the time to copy database values. If you look after extra performance, you may prefer cursors. -- **Cursors can feed Swift collections**: +- **Cursors can feed Swift collections.** - Arrays and all types conforming to `RangeReplaceableCollection`: + You will most of the time use `fetchAll` or `fetchSet` when you want an array or a set. For more specific needs, you may prefer one of the initializers below. All of them accept an extra optional `minimumCapacity` argument which helps optimizing your app when you have an idea of the number of elements in a cursor (the built-in `fetchAll` and `fetchSet` do not perform such an optimization). + + **Arrays** and all types conforming to `RangeReplaceableCollection`: ```swift // [String] @@ -825,7 +827,7 @@ try dbQueue.read { db in let array = try Array(cursor) ``` - Sets: + **Sets**: ```swift // Set @@ -833,7 +835,7 @@ try dbQueue.read { db in let set = try Set(cursor) ``` - Dictionaries: + **Dictionaries**: ```swift // [Int64: [Player]] @@ -844,8 +846,6 @@ try dbQueue.read { db in let cursor = try Player.fetchCursor(db).map { ($0.id, $0) } let dictionary = try Dictionary(uniqueKeysWithValues: cursor) ``` - - > :bulb: **Tip**: all those initializers accept an extra `minimumCapacity` argument which helps optimizing your app when you have an idea of the number of elements fetched by the cursor. - **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/5.5/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: