diff --git a/CHANGELOG.md b/CHANGELOG.md index ce202e6de..9ea5718c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Release Notes ============= +## Next Version + +### Breaking Changes + +- The DatabaseReader and DatabaseWriter protocols have changed in a way that is compatible with your current code, except with your eventual custom types that implement those protocols. Only five types provided by GRDB adopt those propocols: DatabaseQueue, DatabasePool, DatabaseSnapshot, AnyDatabaseReader, and AnyDatabaseWriter. Expanding this set is no longer supported. + + ## 3.4.0 Released October 8, 2018 • [diff](https://github.com/groue/GRDB.swift/compare/v3.3.1...v3.4.0) diff --git a/README.md b/README.md index bce0a6206..b1c6ad953 100644 --- a/README.md +++ b/README.md @@ -7362,7 +7362,25 @@ These protocols provide a unified API that let you write generic code that targe - [FetchedRecordsController](#fetchedrecordscontroller) - [RxGRDB](http://github.com/RxSwiftCommunity/RxGRDB) -Caution: DatabaseReader and DatabaseWriter only provide the *smallest* common guarantees. They don't erase the differences between queues, pools, and snapshots. See for example [Differences between Database Queues and Pools](#differences-between-database-queues-and-pools). +Only five types adopt those protocols: DatabaseQueue, DatabasePool, DatabaseSnapshot, AnyDatabaseReader, and AnyDatabaseWriter. Expanding this set is not supported: any future GRDB release may break your custom writers and readers, without notice. + +DatabaseReader and DatabaseWriter provide the *smallest* common guarantees: they don't erase the differences between queues, pools, and snapshots. See for example [Differences between Database Queues and Pools](#differences-between-database-queues-and-pools). + +However, you can easily prevent some parts of your application from writing in the database by giving them a DatabaseReader: + +```swift +// This class can read in the database, but can't write into it. +class MyReadOnlyComponent { + let reader: DatabaseReader + + init(reader: DatabaseReader) { + self.reader = reader + } +} + +let dbQueue: DatabaseQueue = ... +let component = MyReadOnlyComponent(reader: dbQueue) +``` ### Unsafe Concurrency APIs diff --git a/Tests/GRDBTests/CompilationProtocolTests.swift b/Tests/GRDBTests/CompilationProtocolTests.swift index 109d65759..f92531a46 100644 --- a/Tests/GRDBTests/CompilationProtocolTests.swift +++ b/Tests/GRDBTests/CompilationProtocolTests.swift @@ -42,18 +42,6 @@ private class UserDatabaseAggregate2 : DatabaseAggregate { func finalize() throws -> DatabaseValueConvertible? { preconditionFailure() } } -// MARK: - DatabaseReader - -private class UserDatabaseReader : DatabaseReader { - func read(_ block: (Database) throws -> T) throws -> T { preconditionFailure() } - func unsafeRead(_ block: (Database) throws -> T) throws -> T { preconditionFailure() } - func unsafeReentrantRead(_ block: (Database) throws -> T) throws -> T { preconditionFailure() } - func add(function: DatabaseFunction) { } - func remove(function: DatabaseFunction) { } - func add(collation: DatabaseCollation) { } - func remove(collation: DatabaseCollation) { } -} - // MARK: - DatabaseValueConvertible private struct UserDatabaseValueConvertible1 : DatabaseValueConvertible { @@ -66,23 +54,6 @@ private class UserDatabaseValueConvertible2 : DatabaseValueConvertible { static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? { preconditionFailure() } } -// MARK: - DatabaseWriter - -private class UserDatabaseWriter : DatabaseWriter { - func read(_ block: (Database) throws -> T) throws -> T { preconditionFailure() } - func unsafeRead(_ block: (Database) throws -> T) throws -> T { preconditionFailure() } - func unsafeReentrantRead(_ block: (Database) throws -> T) throws -> T { preconditionFailure() } - func add(function: DatabaseFunction) { } - func remove(function: DatabaseFunction) { } - func add(collation: DatabaseCollation) { } - func remove(collation: DatabaseCollation) { } - func write(_ block: (Database) throws -> T) rethrows -> T { preconditionFailure() } - func writeWithoutTransaction(_ block: (Database) throws -> T) rethrows -> T { preconditionFailure() } - func unsafeReentrantWrite(_ block: (Database) throws -> T) rethrows -> T { preconditionFailure() } - func readFromCurrentState(_ block: @escaping (Database) -> Void) throws { preconditionFailure() } - func concurrentRead(_ block: @escaping (Database) throws -> T) -> Future { preconditionFailure() } -} - // MARK: - FTS5Tokenizer #if SQLITE_ENABLE_FTS5