Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
Update to version 5.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Grosmark committed Apr 2, 2021
1 parent 8349220 commit c0fdcb8
Show file tree
Hide file tree
Showing 139 changed files with 2,767 additions and 112,085 deletions.
5 changes: 2 additions & 3 deletions GRDB-xcframework.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Pod::Spec.new do |s|
s.name = 'GRDB-xcframework'

s.module_name = 'GRDB'
s.version = '5.5.0'
s.version = '5.6.0'

s.summary = 'A toolkit for SQLite databases, with a focus on application development.'
s.description = <<-DESC
Expand All @@ -13,8 +13,7 @@ Pod::Spec.new do |s|
s.license = 'MIT'
s.author = { 'Gwendal Roué' => '[email protected]' }

s.source = { :git => '[email protected]:WW-Digital/ios-GRDB.git', :tag => "#{s.version}" }

s.source = { :http => 'https://github.com/WW-Digital/ios-GRDB/releases/download/5.6.0/GRDB.xcframework.zip', :sha256 => 'e0c133bb6b4f32167d5cc8c3dceaefa79b1a264a6e79d588a3703f5819ef0797' }
s.requires_arc = true

s.vendored_frameworks = 'GRDB.xcframework'
Expand Down
21 changes: 21 additions & 0 deletions GRDB.swift/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:

#### 5.x Releases

- `5.6.x` Releases - [5.6.0](#560)
- `5.5.x` Releases - [5.5.0](#550)
- `5.4.x` Releases - [5.4.0](#540)
- `5.3.x` Releases - [5.3.0](#530)
Expand Down Expand Up @@ -71,6 +72,26 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
- [0.110.0](#01100), ...


## 5.6.0

Released March 12, 2021 &bull; [diff](https://github.com/groue/GRDB.swift/compare/v5.5.0...v5.6.0)

- **Fixed**: [#933](https://github.com/groue/GRDB.swift/pull/933): Fix DatabaseMigrator.eraseDatabaseOnSchemaChange in the context of shared databases

- **Fixed**: [#934](https://github.com/groue/GRDB.swift/pull/934): Fix a crash in the ValueObservation publisher

- **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)).

- **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).

- **Documentation update**: The [Good Practices for Designing Record Types](Documentation/GoodPracticesForDesigningRecordTypes.md) guide has an updated [Define Record Requests](Documentation/GoodPracticesForDesigningRecordTypes.md#define-record-requests) chapter, now that the `DerivableRequest` protocol has access to `limit`, `distinct`, `group`, `having`, association aggregates, and common table expressions.

- **Documentation update**: The [Good Practices for Designing Record Types](Documentation/GoodPracticesForDesigningRecordTypes.md) guide has a new chapter of good practices: [Record Types Hide Intimate Database Details](Documentation/GoodPracticesForDesigningRecordTypes.md#record-types-hide-intimate-database-details).

- **Documentation update**: A new [Single-Row Tables](Documentation/SingleRowTables.md) guide provides guidance for designing tables that store configuration values, user preferences, and generally some global application state.

## 5.5.0

Released March 3, 2021 &bull; [diff](https://github.com/groue/GRDB.swift/compare/v5.4.0...v5.5.0)
Expand Down
133 changes: 131 additions & 2 deletions GRDB.swift/Documentation/AssociationsBasics.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ GRDB Associations
- [Sorting Associations]
- [Ordered Associations]
- [Columns Selected by an Association]
- [Further Refinements to Associations]
- [Table Aliases]
- [Refining Association Requests]
- [Fetching Values from Associations]
Expand Down Expand Up @@ -781,6 +782,7 @@ Fetch requests do not visit the database until you fetch values from them. This
- [Sorting Associations]
- [Ordered Associations]
- [Columns Selected by an Association]
- [Further Refinements to Associations]
- [Table Aliases]
- [Refining Association Requests]

Expand Down Expand Up @@ -855,14 +857,22 @@ Before we describe them in detail, let's see a few requests they can build:
let request = Author
.including(all: Author.books)

/// All authors with their three most popular books
let request = Author
.including(all: Author.books.order(Column("popularity").desc).limit(3))

/// All authors with their awarded books
let request = Author
.including(all: Author.books.having(Book.awards.isEmpty == false))

/// All books with their respective author
let request = Book
.including(required: Book.author)

/// All books with their respective author, sorted by title
let request = Book
.order(Column("title"))
.including(required: Book.author)
.order(Column("title"))

/// All books written by a French author
let request = Book
Expand Down Expand Up @@ -1235,7 +1245,6 @@ let teamInfos = try Team
.fetchAll(db)
```


## Columns Selected by an Association

By default, associated records include all their columns:
Expand All @@ -1262,6 +1271,124 @@ let request = Book.including(required: restrictedAuthor)
To specify the default selection for all inclusions of a given type, see [Columns Selected by a Request](../README.md#columns-selected-by-a-request).


## Further Refinements to Associations

Associations support more refinements:

- `limit`

Fetch all authors with their three most popular books:

```swift
struct AuthorInfo: FetchableRecord, Decodable {
var author: Author
var books: [Book]
}

let mostPopularBooks = Author.books
.order(Column("popularity").desc)
.limit(3)

let authorInfos: [AuthorInfo] = try Author
.including(all: mostPopularBooks)
.asRequest(of: AuthorInfo.self)
.fetchAll(db)
```

- `distinct`

Fetch all authors with the kinds of books they write (novels, poems, plays, etc):

```swift
struct AuthorInfo: Decodable, FetchableRecord {
var author: Author
var bookKinds: Set<Book.Kind>
}

let distinctBookKinds = Author.books
.select(Column("kind"))
.distinct()
.forKey("bookKinds")

let authorInfos: [AuthorInfo] = try Author
.including(all: distinctBookKinds)
.asRequest(of: AuthorInfo.self)
.fetchAll(db)
```

- `group`, `having`

Fetch all authors with the year of their latest book for each kind (novels, poems, plays, etc):

```swift
struct BookKindInfo: Decodable {
var kind: Book.Kind
var maxYear: Int
}

struct AuthorInfo: Decodable, FetchableRecord {
var author: Author
var bookKindInfos: [BookKindInfo]
}

let bookKindInfos = Author.books
.select(
Column("kind"),
max(Column("year")).forKey("maxYear"))
.group(Column("kind"))
.forKey("bookKindInfos")

let authorInfos: [AuthorInfo] = try Author
.including(all: bookKindInfos)
.asRequest(of: AuthorInfo.self)
.fetchAll(db)
```

- [Association Aggregates]

Fetch all authors with their awarded books:

```swift
struct AuthorInfo: FetchableRecord, Decodable {
var author: Author
var awardedBooks: [Book]
}

let awardedBooks = Author.books
.having(Book.awards.isEmpty == false)
.forKey("awardedBooks")

let authorInfos: [AuthorInfo] = try Author
.including(all: awardedBooks)
.asRequest(of: AuthorInfo.self)
.fetchAll(db)
```

- [Common Table Expressions]

Association can use their own CTEs:

```swift
struct AuthorInfo: FetchableRecord, Decodable {
var author: Author
var specialBooks: [Book]
}

let specialCTE = CommonTableExpression(...)
let specialBooks = Author.books
.with(specialCTE)
... // use the CTE in the book association
.forKey("specialBooks")

let authorInfos = try Author
.including(all: specialBooks)
.asRequest(of: AuthorInfo.self)
.fetchAll(db)
```

> :warning: **Warning**: associations refined with `limit`, `distinct`, `group`, `having`, or association aggregates can only be used with `including(all:)`. You will get a fatal error if you use them with other joining methods: `including(required:)`, etc.


## Table Aliases

In all examples we have seen so far, all associated records are joined, included, filtered, and sorted independently. We could not filter them on conditions that involve several records, for example.
Expand Down Expand Up @@ -2447,6 +2574,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[Choosing Between BelongsTo and HasOne]: #choosing-between-belongsto-and-hasone
[Self Joins]: #self-joins
[Ordered Associations]: #ordered-associations
[Further Refinements to Associations]: #further-refinements-to-associations
[The Types of Associations]: #the-types-of-associations
[FetchableRecord]: ../README.md#fetchablerecord-protocols
[migration]: Migrations.md
Expand Down Expand Up @@ -2497,4 +2625,5 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[ValueObservation]: ../README.md#valueobservation
[FAQ]: ../README.md#faq-associations
[common table expressions]: CommonTableExpressions.md
[Common Table Expressions]: CommonTableExpressions.md
[Associations to Common Table Expressions]: CommonTableExpressions.md#associations-to-common-table-expressions
4 changes: 2 additions & 2 deletions GRDB.swift/Documentation/FullTextSearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ let pattern = FTS3Pattern(matchingAnyTokenIn: "") // nil
let pattern = FTS3Pattern(matchingAnyTokenIn: "*") // nil
```

FTS3Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.5/Structs/StatementArguments.html):
FTS3Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.6/Structs/StatementArguments.html):

```swift
let documents = try Document.fetchAll(db,
Expand Down Expand Up @@ -529,7 +529,7 @@ let pattern = FTS5Pattern(matchingAnyTokenIn: "") // nil
let pattern = FTS5Pattern(matchingAnyTokenIn: "*") // nil
```

FTS5Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.5/Structs/StatementArguments.html):
FTS5Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.6/Structs/StatementArguments.html):

```swift
let documents = try Document.fetchAll(db,
Expand Down
Loading

0 comments on commit c0fdcb8

Please sign in to comment.