From c5203f078da7c5d1a676e173dca8dab972e750b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gwendal=20Roue=CC=81?=
Date: Thu, 30 Nov 2023 07:56:21 +0100
Subject: [PATCH 1/3] Make Database.readOnly public
---
GRDB/Core/Database.swift | 36 +++++++++++++++++++++++++----
Tests/GRDBTests/DatabaseTests.swift | 3 +--
2 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift
index 46fca6c06..153bedd8a 100644
--- a/GRDB/Core/Database.swift
+++ b/GRDB/Core/Database.swift
@@ -109,6 +109,7 @@ let SQLITE_TRANSIENT = unsafeBitCast(OpaquePointer(bitPattern: -1), to: sqlite3_
/// - ``checkpoint(_:on:)``
/// - ``clearSchemaCache()``
/// - ``logError``
+/// - ``readOnly(_:)``
/// - ``releaseMemory()``
/// - ``trace(options:_:)``
/// - ``CheckpointMode``
@@ -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/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
From e3cf966c81b8ea3e3750b65ba2484027abdfb9d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gwendal=20Roue=CC=81?=
Date: Fri, 1 Dec 2023 08:02:32 +0100
Subject: [PATCH 2/3] Documentation organization
---
GRDB/Core/Database.swift | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift
index 153bedd8a..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``
@@ -109,7 +110,6 @@ let SQLITE_TRANSIENT = unsafeBitCast(OpaquePointer(bitPattern: -1), to: sqlite3_
/// - ``checkpoint(_:on:)``
/// - ``clearSchemaCache()``
/// - ``logError``
-/// - ``readOnly(_:)``
/// - ``releaseMemory()``
/// - ``trace(options:_:)``
/// - ``CheckpointMode``
From e31a80e3c445a91c07215709a6ad1358090c5896 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gwendal=20Roue=CC=81?=
Date: Fri, 1 Dec 2023 08:06:55 +0100
Subject: [PATCH 3/3] v6.23.0
---
CHANGELOG.md | 7 +++++++
GRDB.swift.podspec | 2 +-
README.md | 2 +-
Support/Info.plist | 2 +-
4 files changed, 10 insertions(+), 3 deletions(-)
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/README.md b/README.md
index f62d22fef..0375543b3 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@
-**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