diff --git a/BRAG.md b/BRAG.md index 989b2fb0d..8e778f235 100644 --- a/BRAG.md +++ b/BRAG.md @@ -4,6 +4,12 @@ Here is a list of people who were happy to meet GRDB :-) --- +https://twitter.com/layoutsubviews/status/1249940744929816582 + +> Mixing SQLite / GRDB with Combine is my whole world right now, and it is delightful. + +--- + https://twitter.com/steipete/status/1231105339954802694 > It [Core Data] gets the job done, but folks made some really amazing Swift native sqlite wrappers. diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b188a3e4..0284fde25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: #### 4.x Releases -- `4.12.x` Releases - [4.12.0](#4120) | [4.12.1](#4121) +- `4.13.x` Releases - [4.13.0](#4130) +- `4.12.x` Releases - [4.12.0](#4120) | [4.12.1](#4121) | [4.12.2](#4122) - `4.11.x` Releases - [4.11.0](#4110) - `4.10.x` Releases - [4.10.0](#4100) - `4.9.x` Releases - [4.9.0](#490) @@ -108,6 +109,29 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: - [#752](https://github.com/groue/GRDB.swift/pull/752): Remove ValueObservation.combine +## 4.13.0 + +Released April 15, 2020 • [diff](https://github.com/groue/GRDB.swift/compare/v4.12.2...v4.13.0) + +**Fixed** + +- Restored support for Xcode 10.0 and Xcode 10.1, broken in 4.12.2 +- [#759](https://github.com/groue/GRDB.swift/pull/759): Fix batch updates of complex requests + +**New** + +- [#761](https://github.com/groue/GRDB.swift/pull/761): Deprecate the batch update `<-` operator + + +## 4.12.2 + +Released April 13, 2020 • [diff](https://github.com/groue/GRDB.swift/compare/v4.12.1...v4.12.2) + +**Fixed** + +- [#757](https://github.com/groue/GRDB.swift/pull/757): Don't load association inflections unless necessary + + ## 4.12.1 Released March 29, 2020 • [diff](https://github.com/groue/GRDB.swift/compare/v4.12.0...v4.12.1) diff --git a/Documentation/GRDB5MigrationGuide.md b/Documentation/GRDB5MigrationGuide.md index 4cf9fce0f..61ee0778c 100644 --- a/Documentation/GRDB5MigrationGuide.md +++ b/Documentation/GRDB5MigrationGuide.md @@ -11,7 +11,7 @@ Migrating From GRDB 4 to GRDB 5 ## Preparing the Migration to GRDB 5 -If you haven't made it yet, upgrade to GRDB 4.12.1 first, and fix any deprecation warning prior to the GRDB 5 upgrade. +If you haven't made it yet, upgrade to the [latest GRDB 4 release](https://github.com/groue/GRDB.swift/tags) first, and fix any deprecation warning prior to the GRDB 5 upgrade. GRDB 5 ships with fix-its that will suggest simple syntactic changes, and won't require you to think much. diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index ab4e46d8e..4d1efa0a6 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '4.12.1' + s.version = '4.13.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift index aaa1f88f8..06e6a09d4 100644 --- a/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift @@ -279,24 +279,23 @@ struct SQLQueryGenerator { var context = SQLGenerationContext.queryContext(aliases: relation.allAliases) - // SELECT rowid FROM table ... - var generator = self - generator.relation = generator.relation.selectOnly([Column.rowID]) - let selectSQL = try generator.sql(db, &context) - + // UPDATE table... var sql = "UPDATE " - if conflictResolution != .abort { sql += "OR \(conflictResolution.rawValue) " } - sql += tableName.quotedDatabaseIdentifier + // SET column = value... let assignmentsSQL = assignments .map { $0.sql(&context) } .joined(separator: ", ") sql += " SET " + assignmentsSQL - sql += " WHERE rowid IN (\(selectSQL))" + + // WHERE rowid IN (SELECT rowid FROM ...) + var generator = self + generator.relation = generator.relation.selectOnly([Column.rowID]) + sql += try " WHERE rowid IN (\(generator.sql(db, &context)))" let statement = try db.makeUpdateStatement(sql: sql) statement.arguments = context.arguments diff --git a/GRDB/Utils/Inflections.swift b/GRDB/Utils/Inflections.swift index af1f05fd3..d93d7acc7 100644 --- a/GRDB/Utils/Inflections.swift +++ b/GRDB/Utils/Inflections.swift @@ -9,14 +9,22 @@ extension String { return String(first).uppercased() + dropFirst() } + // Prevent inlining of functions that use `Inflections.default`, in order to + // make sure this global is lazily loaded, even in release builds. + // See https://github.com/groue/GRDB.swift/issues/755#issuecomment-612418053 + // TODO: remove `@inline(never)` when this PR is shipped in the compiler: + // https://github.com/apple/swift/pull/30445 + /// "player" -> "players" /// "players" -> "players" + @inline(never) var pluralized: String { Inflections.default.pluralize(self) } /// "player" -> "player" /// "players" -> "player" + @inline(never) var singularized: String { Inflections.default.singularize(self) } diff --git a/Makefile b/Makefile index 131c09390..982b264bb 100644 --- a/Makefile +++ b/Makefile @@ -387,10 +387,10 @@ ifdef JAZZY --author 'Gwendal RouĂ©' \ --author_url https://github.com/groue \ --github_url https://github.com/groue/GRDB.swift \ - --github-file-prefix https://github.com/groue/GRDB.swift/tree/v4.12.1 \ - --module-version 4.12.1 \ + --github-file-prefix https://github.com/groue/GRDB.swift/tree/v4.13.0 \ + --module-version 4.13.0 \ --module GRDB \ - --root-url http://groue.github.io/GRDB.swift/docs/4.12/ \ + --root-url http://groue.github.io/GRDB.swift/docs/4.13/ \ --output Documentation/Reference \ --xcodebuild-arguments -project,GRDB.xcodeproj,-scheme,GRDBiOS else diff --git a/README.md b/README.md index 9de5f7608..9fea30d39 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ | Swift version | GRDB version | | ------------- | ----------------------------------------------------------- | | **Swift 5.2** | [GRDB5 branch](https://github.com/groue/GRDB.swift/tree/GRDB5) | -| Swift 5.1 | [v4.12.1](https://github.com/groue/GRDB.swift/tree/v4.12.0) | -| Swift 5 | [v4.12.1](https://github.com/groue/GRDB.swift/tree/v4.12.0) | -| Swift 4.2 | [v4.12.1](https://github.com/groue/GRDB.swift/tree/v4.12.0) | +| Swift 5.1 | [v4.13.0](https://github.com/groue/GRDB.swift/tree/v4.13.0) | +| Swift 5 | [v4.13.0](https://github.com/groue/GRDB.swift/tree/v4.13.0) | +| Swift 4.2 | [v4.13.0](https://github.com/groue/GRDB.swift/tree/v4.13.0) | | Swift 4.1 | [v3.7.0](https://github.com/groue/GRDB.swift/tree/v3.7.0) | | Swift 4 | [v2.10.0](https://github.com/groue/GRDB.swift/tree/v2.10.0) | | Swift 3.2 | [v1.3.0](https://github.com/groue/GRDB.swift/tree/v1.3.0) | @@ -263,7 +263,7 @@ Documentation #### Reference -- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/4.12/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) +- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/4.13/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) #### Getting Started @@ -478,7 +478,7 @@ let dbQueue = try DatabaseQueue( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/4.12/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/4.13/Structs/Configuration.html) for more details. ## Database Pools @@ -559,7 +559,7 @@ let dbPool = try DatabasePool( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/4.12/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/4.13/Structs/Configuration.html) for more details. Database pools are more memory-hungry than database queues. See [Memory Management](#memory-management) for more information. @@ -619,7 +619,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.12/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. You can also embed query arguments right into your SQL queries, with the `literal` argument label, as in the example below. See [SQL Interpolation] for more details. @@ -817,7 +817,7 @@ Both arrays and cursors can iterate over database results. How do you choose one - **Cursors are granted with direct access to SQLite,** unlike arrays that have to take the time to copy database values. If you look after extra performance, you may prefer cursors over arrays. -- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/4.12/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`: +- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/4.13/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`: ```swift // Prints all Github links @@ -899,7 +899,7 @@ let rows = try Row.fetchAll(db, arguments: ["name": "Arthur"]) ``` -See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.12/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. Unlike row arrays that contain copies of the database rows, row cursors are close to the SQLite metal, and require a little care: @@ -1182,7 +1182,7 @@ GRDB ships with built-in support for the following value types: - Generally speaking, all types that adopt the [DatabaseValueConvertible](#custom-value-types) protocol. -Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/4.12/Structs/StatementArguments.html): +Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html): ```swift let url: URL = ... @@ -1589,7 +1589,7 @@ try dbQueue.inDatabase { db in // or dbPool.writeWithoutTransaction } ``` -Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/4.12/Structs/Configuration.html) configuration flag: +Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/4.13/Structs/Configuration.html) configuration flag: ```swift // fatal error: A transaction has been left opened at the end of a database access @@ -1703,7 +1703,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.12/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). +The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). ```swift updateStatement.arguments = ["name": "Arthur", "score": 1000] @@ -1962,7 +1962,7 @@ row["consumed"] // "Hello" row["produced"] // nil ``` -Row adapters are values that adopt the [RowAdapter](http://groue.github.io/GRDB.swift/docs/4.12/Protocols/RowAdapter.html) protocol. You can implement your own custom adapters ([**:fire: EXPERIMENTAL**](#what-are-experimental-features)), or use one of the four built-in adapters, described below. +Row adapters are values that adopt the [RowAdapter](http://groue.github.io/GRDB.swift/docs/4.13/Protocols/RowAdapter.html) protocol. You can implement your own custom adapters ([**:fire: EXPERIMENTAL**](#what-are-experimental-features)), or use one of the four built-in adapters, described below. To see how row adapters can be used, see [Joined Queries Support](#joined-queries-support). @@ -2417,7 +2417,7 @@ try Place.fetchAll(db, sql: "SELECT ...", arguments:...) // [Place] try Place.fetchOne(db, sql: "SELECT ...", arguments:...) // Place? ``` -See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.12/Structs/StatementArguments.html) for more information about the query arguments. +See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html) for more information about the query arguments. > :point_up: **Note**: for performance reasons, the same row argument to `init(row:)` is reused during the iteration of a fetch query. If you want to keep the row for later use, make sure to store a copy: `self.row = row.copy()`. @@ -2796,7 +2796,7 @@ protocol EncodableRecord { } ``` -See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/4.12/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.12/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.12/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. +See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/4.13/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.13/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.13/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. > :point_up: **Note**: there is no customization of uuid decoding, because UUID can already decode all its encoded variants (16-bytes blobs, and uuid strings). @@ -3427,7 +3427,7 @@ extension Place: MutablePersistableRecord {
Define a plain struct optimized for fetching performance -This struct derives is persistence methpds from the standard Encodable protocol (see [Codable Records]), but performs optimized row decoding by accessing database columns with numeric indexes. +This struct derives its persistence methods from the standard Encodable protocol (see [Codable Records]), but performs optimized row decoding by accessing database columns with numeric indexes. See the [Record Protocols Overview](#record-protocols-overview) for more information. @@ -4181,7 +4181,7 @@ Player // SELECT * FROM player ``` -Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/4.12/Structs/StatementArguments.html): +Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/4.13/Structs/StatementArguments.html): ```swift // SELECT DATE(creationDate), COUNT(*) FROM player WHERE name = 'Arthur' GROUP BY date(creationDate) @@ -4799,7 +4799,7 @@ let request = Player.all() **To build custom requests**, you can use one of the built-in requests, derive requests from other requests, or create your own request type that adopts the [FetchRequest](#fetchrequest-protocol) protocol. -- [SQLRequest](http://groue.github.io/GRDB.swift/docs/4.12/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example: +- [SQLRequest](http://groue.github.io/GRDB.swift/docs/4.13/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example: ```swift extension Player { @@ -4842,7 +4842,7 @@ let request = Player.all() - The `adapted(_:)` method eases the consumption of complex rows with [row adapters](#row-adapters). See [Joined Queries Support](#joined-queries-support) for some sample code that uses this method. -- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/4.12/Structs/AnyFetchRequest.html): a [type-erased](http://chris.eidhof.nl/post/type-erasers-in-swift/) request. +- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/4.13/Structs/AnyFetchRequest.html): a [type-erased](http://chris.eidhof.nl/post/type-erasers-in-swift/) request. ### Fetching From Custom Requests @@ -6197,7 +6197,7 @@ After `stopObservingDatabaseChangesUntilNextTransaction()`, the `databaseDidChan ### DatabaseRegion -**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/4.12/Structs/DatabaseRegion.html) is a type that helps observing changes in the results of a database [request](#requests)**. +**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/4.13/Structs/DatabaseRegion.html) is a type that helps observing changes in the results of a database [request](#requests)**. A request knows which database modifications can impact its results. It can communicate this information to [transaction observers](#transactionobserver-protocol) by the way of a DatabaseRegion. @@ -6207,7 +6207,7 @@ DatabaseRegion fuels, for example, [ValueObservation and DatabaseRegionObservati For example, if you observe the region of `Player.select(max(Column("score")))`, then you'll get be notified of all changes performed on the `score` column of the `player` table (updates, insertions and deletions), even if they do not modify the value of the maximum score. However, you will not get any notification for changes performed on other database tables, or updates to other columns of the player table. -For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/4.12/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). +For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/4.13/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). #### The DatabaseRegionConvertible Protocol @@ -7302,7 +7302,7 @@ try snapshot2.read { db in ### DatabaseWriter and DatabaseReader Protocols -Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/4.12/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/4.12/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. +Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/4.13/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/4.13/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. These protocols provide a unified API that let you write generic code that targets all concurrency modes. They fuel, for example: diff --git a/Support/Info.plist b/Support/Info.plist index 0d1771ddc..b8315a49b 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.12.1 + 4.13.0 CFBundleSignature ???? CFBundleVersion diff --git a/Tests/GRDBTests/MutablePersistableRecordUpdateTests.swift b/Tests/GRDBTests/MutablePersistableRecordUpdateTests.swift index c750baf52..cc43f4fef 100644 --- a/Tests/GRDBTests/MutablePersistableRecordUpdateTests.swift +++ b/Tests/GRDBTests/MutablePersistableRecordUpdateTests.swift @@ -428,6 +428,16 @@ class MutablePersistableRecordUpdateTests: GRDBTestCase { JOIN "team" ON "team"."id" = "player"."teamId") """) } + do { + // Regression test for https://github.com/groue/GRDB.swift/issues/758 + try Player.including(required: Player.team.filter(Column("active") == 1)).updateAll(db, Column("score").set(to: 0)) + XCTAssertEqual(self.lastSQLQuery, """ + UPDATE "player" SET "score" = 0 WHERE rowid IN (\ + SELECT "player"."rowid" \ + FROM "player" \ + JOIN "team" ON ("team"."id" = "player"."teamId") AND ("team"."active" = 1)) + """) + } do { let alias = TableAlias(name: "p") try Player.aliased(alias).including(required: Player.team).updateAll(db, Column("score").set(to: 0))