From a0faf6aa6840ea8a04f383a32d50e8d86b262ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 18 Mar 2020 19:34:43 +0100 Subject: [PATCH 1/6] Support for nil assignment --- CHANGELOG.md | 7 +++++++ .../Request/QueryInterfaceRequest.swift | 16 ++++++++++++++-- .../SQLGeneration/SQLQueryGenerator.swift | 12 ++---------- README.md | 4 ++-- .../MutablePersistableRecordUpdateTests.swift | 11 +++++++++++ 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14cd76cef..9198d105e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,13 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: **New** +- Batch updates now accept nil assignments: + + ```swift + // UPDATE player SET score = NULL + try Player.updateAll(db, scoreColumn <- nil) + ``` + - DatabaseMigrator querying methods have been enhanced: ```swift diff --git a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift index f0cc36f57..1bb0fcd03 100644 --- a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift @@ -644,20 +644,32 @@ infix operator <- : ColumnAssignment /// } public struct ColumnAssignment { var column: ColumnExpression - var value: SQLExpressible + var value: SQLExpressible? + + func sql(_ context: inout SQLGenerationContext) -> String { + if let value = value { + return column.expressionSQL(&context, wrappedInParenthesis: false) + + " = " + + value.sqlExpression.expressionSQL(&context, wrappedInParenthesis: false) + } else { + return column.expressionSQL(&context, wrappedInParenthesis: false) + + " = NULL" + } + } } /// Creates an assignment to a value. /// /// Column("valid") <- true /// Column("score") <- 0 +/// Column("score") <- nil /// Column("score") <- Column("score") + Column("bonus") /// /// try dbQueue.write { db in /// // UPDATE player SET score = 0 /// try Player.updateAll(db, Column("score") <- 0) /// } -public func <- (column: ColumnExpression, value: SQLExpressible) -> ColumnAssignment { +public func <- (column: ColumnExpression, value: SQLExpressible?) -> ColumnAssignment { return ColumnAssignment(column: column, value: value) } diff --git a/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift index 7114af533..bc017284a 100644 --- a/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift +++ b/GRDB/QueryInterface/SQLGeneration/SQLQueryGenerator.swift @@ -228,11 +228,7 @@ struct SQLQueryGenerator { sql += try relation.source.sql(db, &context) let assignmentsSQL = assignments - .map({ assignment in - assignment.column.expressionSQL(&context, wrappedInParenthesis: false) + - " = " + - assignment.value.sqlExpression.expressionSQL(&context, wrappedInParenthesis: false) - }) + .map { $0.sql(&context) } .joined(separator: ", ") sql += " SET " + assignmentsSQL @@ -297,11 +293,7 @@ struct SQLQueryGenerator { sql += tableName.quotedDatabaseIdentifier let assignmentsSQL = assignments - .map({ assignment in - assignment.column.expressionSQL(&context, wrappedInParenthesis: false) + - " = " + - assignment.value.sqlExpression.expressionSQL(&context, wrappedInParenthesis: false) - }) + .map { $0.sql(&context) } .joined(separator: ", ") sql += " SET " + assignmentsSQL sql += " WHERE rowid IN (\(selectSQL))" diff --git a/README.md b/README.md index 669793c33..55093ff56 100644 --- a/README.md +++ b/README.md @@ -4699,8 +4699,8 @@ Player.deleteOne(db, key: ["email": "arthur@example.com"]) **Requests can batch update records**. The `updateAll()` method accepts *column assignments* defined with the `<-` operator: ```swift -// UPDATE player SET score = 0, isHealthy = 1 -try Player.updateAll(db, scoreColumn <- 0, isHealthyColumn <- true) +// UPDATE player SET score = 0, isHealthy = 1, bonus = NULL +try Player.updateAll(db, scoreColumn <- 0, isHealthyColumn <- true, bonus <- nil) // UPDATE player SET score = 0 WHERE team = 'red' try Player diff --git a/Tests/GRDBTests/MutablePersistableRecordUpdateTests.swift b/Tests/GRDBTests/MutablePersistableRecordUpdateTests.swift index 7c85037e5..b024d590d 100644 --- a/Tests/GRDBTests/MutablePersistableRecordUpdateTests.swift +++ b/Tests/GRDBTests/MutablePersistableRecordUpdateTests.swift @@ -106,6 +106,17 @@ class MutablePersistableRecordUpdateTests: GRDBTestCase { } } + func testNilAssignment() throws { + try makeDatabaseQueue().write { db in + try Player.createTable(db) + + try Player.updateAll(db, Columns.score <- nil) + XCTAssertEqual(self.lastSQLQuery, """ + UPDATE "player" SET "score" = NULL + """) + } + } + func testComplexAssignment() throws { try makeDatabaseQueue().write { db in try Player.createTable(db) From c1d1797576977e1b1af1a1346b005cf189b9569a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 18 Mar 2020 20:36:56 +0100 Subject: [PATCH 2/6] Address #725 --- GRDB/Migration/DatabaseMigrator.swift | 80 +++++++++++++-------- Tests/GRDBTests/DatabaseMigratorTests.swift | 27 +++++++ 2 files changed, 78 insertions(+), 29 deletions(-) diff --git a/GRDB/Migration/DatabaseMigrator.swift b/GRDB/Migration/DatabaseMigrator.swift index b34618f59..9884de4c9 100644 --- a/GRDB/Migration/DatabaseMigrator.swift +++ b/GRDB/Migration/DatabaseMigrator.swift @@ -142,30 +142,44 @@ public struct DatabaseMigrator { public func migrate(_ writer: DatabaseWriter, upTo targetIdentifier: String) throws { try writer.barrierWriteWithoutTransaction { db in if eraseDatabaseOnSchemaChange { - // Fetch information about current database state - var info: (lastAppliedIdentifier: String, schema: SchemaInfo)? + var needsErase = false try db.inTransaction(.deferred) { - if let lastAppliedIdentifier = try appliedMigrations(db).last { - info = try (lastAppliedIdentifier: lastAppliedIdentifier, schema: db.schema()) + let appliedIdentifiers = try self.appliedIdentifiers(db) + let knownIdentifiers = Set(migrations.map { $0.identifier }) + if !appliedIdentifiers.isSubset(of: knownIdentifiers) { + // Database contains an unknown migration + needsErase = true + return .commit } + + if let lastAppliedIdentifier = migrations.lazy + .map({ $0.identifier }) + .last(where: { appliedIdentifiers.contains($0) }) + { + // Database has been partially migrated. + // + // Create a temporary witness database (on disk, just in case + // migrations would involve a lot of data). + let witness = try DatabaseQueue(path: "", configuration: writer.configuration) + + // Grab schema of migrated witness database + let witnessSchema: SchemaInfo = try witness.writeWithoutTransaction { db in + try runMigrations(db, upTo: lastAppliedIdentifier) + return try db.schema() + } + + // Erase database if we detect a schema change + if try db.schema() != witnessSchema { + needsErase = true + return .commit + } + } + return .commit } - if let info = info { - // Create a temporary witness database (on disk, just in case - // migrations would involve a lot of data). - let witness = try DatabaseQueue(path: "", configuration: writer.configuration) - - // Grab schema of migrated witness database - let witnessSchema: SchemaInfo = try witness.writeWithoutTransaction { db in - try runMigrations(db, upTo: info.lastAppliedIdentifier) - return try db.schema() - } - - // Erase database if we detect a schema change - if info.schema != witnessSchema { - try db.erase() - } + if needsErase { + try db.erase() } } @@ -191,16 +205,8 @@ public struct DatabaseMigrator { /// - parameter db: A database connection. /// - throws: An eventual database error. public func appliedMigrations(_ db: Database) throws -> [String] { - do { - let appliedIdentifiers = try Set(String.fetchCursor(db, sql: "SELECT identifier FROM grdb_migrations")) - return migrations.map { $0.identifier }.filter { appliedIdentifiers.contains($0) } - } catch { - // Rethrow if we can't prove grdb_migrations does not exist yet - if (try? !db.tableExists("grdb_migrations")) ?? false { - return [] - } - throw error - } + let appliedIdentifiers = try self.appliedIdentifiers(db) + return migrations.map { $0.identifier }.filter { appliedIdentifiers.contains($0) } } /// Returns the identifiers of completed migrations, of which all previous @@ -264,6 +270,22 @@ public struct DatabaseMigrator { migrations.append(migration) } + /// Returns the applied migration identifiers, even unregistered ones + /// + /// - parameter db: A database connection. + /// - throws: An eventual database error. + public func appliedIdentifiers(_ db: Database) throws -> Set { + do { + return try Set(String.fetchCursor(db, sql: "SELECT identifier FROM grdb_migrations")) + } catch { + // Rethrow if we can't prove grdb_migrations does not exist yet + if (try? !db.tableExists("grdb_migrations")) ?? false { + return [] + } + throw error + } + } + /// Returns unapplied migration identifier, private func unappliedMigrations(upTo targetIdentifier: String, appliedIdentifiers: [String]) -> [Migration] { var expectedMigrations: [Migration] = [] diff --git a/Tests/GRDBTests/DatabaseMigratorTests.swift b/Tests/GRDBTests/DatabaseMigratorTests.swift index fdfc06236..ce8e8d8c5 100644 --- a/Tests/GRDBTests/DatabaseMigratorTests.swift +++ b/Tests/GRDBTests/DatabaseMigratorTests.swift @@ -674,4 +674,31 @@ class DatabaseMigratorTests : GRDBTestCase { try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, sql: "SELECT id FROM t1") }, 1) try XCTAssertTrue(dbQueue.read { try $0.tableExists("t2") }) } + + func testEraseDatabaseOnSchemaChangeWithRenamedMigration() throws { + let dbQueue = try makeDatabaseQueue() + + // 1st migration + var migrator1 = DatabaseMigrator() + migrator1.registerMigration("1") { db in + try db.execute(sql: """ + CREATE TABLE t1(id INTEGER PRIMARY KEY); + INSERT INTO t1(id) VALUES (1) + """) + } + try migrator1.migrate(dbQueue) + try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, sql: "SELECT id FROM t1") }, 1) + + // 2nd migration does not erase database + var migrator2 = DatabaseMigrator() + migrator2.eraseDatabaseOnSchemaChange = true + migrator2.registerMigration("2") { db in + try db.execute(sql: """ + CREATE TABLE t1(id INTEGER PRIMARY KEY); + INSERT INTO t1(id) VALUES (2) + """) + } + try migrator2.migrate(dbQueue) + try XCTAssertEqual(dbQueue.read { try Int.fetchOne($0, sql: "SELECT id FROM t1") }, 2) + } } From cda254bb2d9d25958911b2b08b8399e9bbb55f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 18 Mar 2020 20:43:09 +0100 Subject: [PATCH 3/6] Update documentation for eraseDatabaseOnSchemaChange --- README.md | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 55093ff56..aa978b8b3 100644 --- a/README.md +++ b/README.md @@ -4966,32 +4966,31 @@ if try dbQueue.read(migrator.appliedMigrations).contains("v2") { ### The `eraseDatabaseOnSchemaChange` Option -A DatabaseMigrator can automatically wipe out the full database content, and recreate the whole database from scratch, if it detects that a migration has changed its definition: +A DatabaseMigrator can automatically wipe out the full database content, and recreate the whole database from scratch, if it detects that migrations have changed their definition: ```swift var migrator = DatabaseMigrator() migrator.eraseDatabaseOnSchemaChange = true ``` -Beware! This flag can destroy your precious users' data! +> :warning: **Warning**: This option can destroy your precious users' data! -Yet it may be useful in those two situations: +Setting `eraseDatabaseOnSchemaChange` is useful during application development, as you are still designing migrations, and the schema changes often. -1. During application development, as you are still designing migrations, and the schema changes often. - - In this case, it is recommended that this flag does not ship in the distributed application: - - ```swift - var migrator = DatabaseMigrator() - #if DEBUG - // Speed up development by nuking the database when migrations change - migrator.eraseDatabaseOnSchemaChange = true - #endif - ``` +It is recommended that this option does not ship in the released application: -2. When the database content can easily be recreated, such as a cache for some downloaded data. +```swift +var migrator = DatabaseMigrator() +#if DEBUG +// Speed up development by nuking the database when migrations change +migrator.eraseDatabaseOnSchemaChange = true +#endif +``` -The `eraseDatabaseOnSchemaChange` option triggers a recreation of the database if the migrator detects a *schema change*. A schema change is any difference in the `sqlite_master` table, which contains the SQL used to create database tables, indexes, triggers, and views. +The `eraseDatabaseOnSchemaChange` option triggers a recreation of the database if and only if: + +- A migration has been removed, or renamed. +- A *schema change* is detected. A schema change is any difference in the `sqlite_master` table, which contains the SQL used to create database tables, indexes, triggers, and views. ### Advanced Database Schema Changes From f04efea09c823e73c74872a89dd93a711040688b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 18 Mar 2020 20:47:04 +0100 Subject: [PATCH 4/6] CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9198d105e..00fcbdf3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,8 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: // UPDATE player SET score = NULL try Player.updateAll(db, scoreColumn <- nil) ``` + +- DatabaseMigrator can now recreate the database if a migration has been removed, or renamed (addresses [#725](https://github.com/groue/GRDB.swift/issues/725)). - DatabaseMigrator querying methods have been enhanced: From 24872373c4e2d095f658ef22f302c12f6146d407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Mar 2020 12:26:35 +0100 Subject: [PATCH 5/6] TODO --- TODO.md | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO.md b/TODO.md index e41d29cfa..098b6552c 100644 --- a/TODO.md +++ b/TODO.md @@ -20,6 +20,7 @@ ## Features +- [ ] request.exists(db) as an alternative to fetchOne(db) != nil. Can generate optimized SQL. - [ ] Measure the duration of transactions - [ ] Improve SQL generation for `Player.....fetchCount(db)`, especially with distinct. Try to avoid `SELECT COUNT(*) FROM (SELECT DISTINCT player.* ...)` - [ ] Alternative technique for custom SQLite builds: see the Podfile at https://github.com/CocoaPods/CocoaPods/issues/9104, and https://github.com/clemensg/sqlite3pod From 50f64dc45d7eafa0378d6fa123e21e0216c9e7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Mar 2020 12:54:30 +0100 Subject: [PATCH 6/6] v4.12.0 --- CHANGELOG.md | 9 +++++++++ GRDB.swift.podspec | 2 +- Makefile | 6 +++--- README.md | 42 +++++++++++++++++++++--------------------- Support/Info.plist | 2 +- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00fcbdf3c..14ebd92e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,14 @@ All notable changes to this project will be documented in this file. GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: APIs flagged [**:fire: EXPERIMENTAL**](README.md#what-are-experimental-features). Those are unstable, and may break between any two minor releases of the library. + #### 4.x Releases +- `4.12.x` Releases - [4.12.0](#4120) - `4.11.x` Releases - [4.11.0](#4110) - `4.10.x` Releases - [4.10.0](#4100) - `4.9.x` Releases - [4.9.0](#490) @@ -62,7 +65,13 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: - [0.110.0](#01100), ... + + +## 4.12.0 + +Released March 21, 2020 • [diff](https://github.com/groue/GRDB.swift/compare/v4.11.0...v4.12.0) **New** diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index cef26d10a..43f36d559 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.11.0' + s.version = '4.12.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/Makefile b/Makefile index b47878ecf..a770e0599 100644 --- a/Makefile +++ b/Makefile @@ -466,10 +466,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.11.0 \ - --module-version 4.11.0 \ + --github-file-prefix https://github.com/groue/GRDB.swift/tree/v4.12.0 \ + --module-version 4.12.0 \ --module GRDB \ - --root-url http://groue.github.io/GRDB.swift/docs/4.11/ \ + --root-url http://groue.github.io/GRDB.swift/docs/4.12/ \ --output Documentation/Reference \ --podspec GRDB.swift.podspec else diff --git a/README.md b/README.md index aa978b8b3..52e3e1c8b 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,14 @@ --- -**Latest release**: March 2, 2020 • version 4.11.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 3 to GRDB 4](Documentation/GRDB3MigrationGuide.md) +**Latest release**: March 21, 2020 • version 4.12.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 3 to GRDB 4](Documentation/GRDB3MigrationGuide.md) **Requirements**: iOS 9.0+ / macOS 10.9+ / tvOS 9.0+ / watchOS 2.0+ • Swift 4.2+ / Xcode 10.0+ | Swift version | GRDB version | | ------------- | ----------------------------------------------------------- | -| **Swift 5** | **v4.11.0** | -| **Swift 4.2** | **v4.11.0** | +| **Swift 5** | **v4.12.0** | +| **Swift 4.2** | **v4.12.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.11/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) +- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/4.12/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.11/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/4.12/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.11/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/4.12/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.11/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.12/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. In Swift 5, you can embed query arguments right into your SQL queries, with the `literal` argument label, as in the example below. See [SQL Interpolation] for more details. @@ -820,7 +820,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.11/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.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`: ```swift // Prints all Github links @@ -902,7 +902,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.11/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.12/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: @@ -1185,7 +1185,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.11/Structs/StatementArguments.html): +Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/4.12/Structs/StatementArguments.html): ```swift let url: URL = ... @@ -1592,7 +1592,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.11/Structs/Configuration.html) configuration flag: +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: ```swift // fatal error: A transaction has been left opened at the end of a database access @@ -1706,7 +1706,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.11/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.12/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). ```swift updateStatement.arguments = ["name": "Arthur", "score": 1000] @@ -1965,7 +1965,7 @@ row["consumed"] // "Hello" row["produced"] // nil ``` -Row adapters are values that adopt the [RowAdapter](http://groue.github.io/GRDB.swift/docs/4.11/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.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. To see how row adapters can be used, see [Joined Queries Support](#joined-queries-support). @@ -2427,7 +2427,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.11/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.12/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()`. @@ -2808,7 +2808,7 @@ protocol EncodableRecord { } ``` -See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/4.11/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.11/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/4.11/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. +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. > :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). @@ -4197,7 +4197,7 @@ Player // SELECT * FROM player ``` -Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/4.11/Structs/StatementArguments.html): +Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/4.12/Structs/StatementArguments.html): ```swift // SELECT DATE(creationDate), COUNT(*) FROM player WHERE name = 'Arthur' GROUP BY date(creationDate) @@ -4812,7 +4812,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.11/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example: +- [SQLRequest](http://groue.github.io/GRDB.swift/docs/4.12/Structs/SQLRequest.html) is a fetch request built from raw SQL. For example: ```swift extension Player { @@ -4856,7 +4856,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.11/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.12/Structs/AnyFetchRequest.html): a [type-erased](http://chris.eidhof.nl/post/type-erasers-in-swift/) request. ### Fetching From Custom Requests @@ -6401,7 +6401,7 @@ After `stopObservingDatabaseChangesUntilNextTransaction()`, the `databaseDidChan ### DatabaseRegion -**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/4.11/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.12/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. @@ -6411,7 +6411,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.11/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). +For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/4.12/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). #### The DatabaseRegionConvertible Protocol @@ -7509,7 +7509,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.11/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/4.11/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. +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. 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 739e62260..a8d32d6b4 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.11.0 + 4.12.0 CFBundleSignature ???? CFBundleVersion