diff --git a/CHANGELOG.md b/CHANGELOG.md index 08e2543f8..aa737e379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: #### 6.x Releases +- `6.23.x` Releases - [6.23.0](#6230) - `6.22.x` Releases - [6.22.0](#6220) - `6.21.x` Releases - [6.21.0](#6210) - `6.20.x` Releases - [6.20.0](#6200) - [6.20.1](#6201) - [6.20.2](#6202) @@ -120,6 +121,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --- +## 6.23.0 + +Released December 1, 2023 + +- **New**: [#1462](https://github.com/groue/GRDB.swift/pull/1462) Temporary read-only access + ## 6.22.0 Released November 26, 2023 diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index ae651ad9c..9d4684a99 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '6.22.0' + s.version = '6.23.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 46fca6c06..0e06a8acc 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -60,6 +60,7 @@ let SQLITE_TRANSIENT = unsafeBitCast(OpaquePointer(bitPattern: -1), to: sqlite3_ /// - ``inSavepoint(_:)`` /// - ``inTransaction(_:_:)`` /// - ``isInsideTransaction`` +/// - ``readOnly(_:)`` /// - ``rollback()`` /// - ``transactionDate`` /// - ``TransactionCompletion`` @@ -772,11 +773,38 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib } } - /// Grants read-only access in the wrapped closure. - func readOnly(_ block: () throws -> T) throws -> T { + /// Executes read-only database operations, and returns their result + /// after they have finished executing. + /// + /// Attempts to write throw a ``DatabaseError`` with + /// resultCode `SQLITE_READONLY`. + /// + /// For example: + /// + /// ```swift + /// try dbQueue.write do { db in + /// // Write OK + /// try Player(...).insert(db) + /// + /// try db.readOnly { + /// // Read OK + /// let players = try Player.fetchAll(db) + /// + /// // Throws SQLITE_READONLY + /// try Player(...).insert(db) + /// } + /// } + /// ``` + /// + /// This method is reentrant. + /// + /// - parameter value: A closure that reads from the database. + /// - throws: A ``DatabaseError`` whenever an SQLite error occurs, or the + /// error thrown by `value`. + public func readOnly(_ value: () throws -> T) throws -> T { try beginReadOnly() return try throwingFirstError( - execute: block, + execute: value, finally: endReadOnly) } @@ -1225,7 +1253,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib /// For example: /// /// ```swift - /// try dbQueue.writeWithoutTransaction do { + /// try dbQueue.writeWithoutTransaction do { db in /// try db.inTransaction { /// try db.execute(sql: "INSERT ...") /// return .commit diff --git a/README.md b/README.md index f62d22fef..0375543b3 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ CI Status

-**Latest release**: November 26, 2023 • [version 6.22.0](https://github.com/groue/GRDB.swift/tree/v6.22.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md) +**Latest release**: December 1, 2023 • [version 6.23.0](https://github.com/groue/GRDB.swift/tree/v6.23.0) • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 5 to GRDB 6](Documentation/GRDB6MigrationGuide.md) **Requirements**: iOS 11.0+ / macOS 10.13+ / tvOS 11.0+ / watchOS 4.0+ • SQLite 3.19.3+ • Swift 5.7+ / Xcode 14+ diff --git a/Support/Info.plist b/Support/Info.plist index 30ecbeebf..34aa2dccb 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 6.22.0 + 6.23.0 CFBundleSignature ???? CFBundleVersion diff --git a/Tests/GRDBTests/DatabaseTests.swift b/Tests/GRDBTests/DatabaseTests.swift index 635b852c0..145340ab3 100644 --- a/Tests/GRDBTests/DatabaseTests.swift +++ b/Tests/GRDBTests/DatabaseTests.swift @@ -1,5 +1,5 @@ import XCTest -@testable import GRDB +import GRDB class DatabaseTests : GRDBTestCase { @@ -520,7 +520,6 @@ class DatabaseTests : GRDBTestCase { } } - // Test an internal API func testReadOnly() throws { let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in