Skip to content

Commit fc5ddf2

Browse files
committed
Support for GRDB6
1 parent f2cd8ad commit fc5ddf2

16 files changed

+78
-62
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Release Notes
22
=============
33

4+
## Next Release
5+
6+
- **New**: Support for GRDB 6
7+
- **Breaking Change**: Swift 5.7+ and Xcode 14+ are required.
8+
- **Breaking Change**: iOS 11.0+ / macOS 10.13+ / tvOS 11.0+ / watchOS 4.0+
9+
410
## 2.1.0
511

612
Released October 17, 2021 • [diff](https://github.com/RxSwiftCommunity/RxGRDB/compare/v2.0.0...v2.1.0)
@@ -12,7 +18,7 @@ Released October 17, 2021 • [diff](https://github.com/RxSwiftCommunity/RxGR
1218

1319
Released January 3, 2021 • [diff](https://github.com/RxSwiftCommunity/RxGRDB/compare/v1.0.0...v2.0.0)
1420

15-
- **New**:: Support for RxSwift 6
21+
- **New**: Support for RxSwift 6
1622

1723
## 1.0.0
1824

Documentation/RxGRDBDemo/RxGRDBDemo.xcodeproj/project.pbxproj

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
567515A222C3A7DC00A6FF66 /* World.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567515A122C3A7DC00A6FF66 /* World.swift */; };
2020
567515A422C3A9BC00A6FF66 /* Players.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567515A322C3A9BC00A6FF66 /* Players.swift */; };
2121
567515A822C3B1F100A6FF66 /* PlayersViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 567515A722C3B1F100A6FF66 /* PlayersViewModel.swift */; };
22+
567CE94228CB747200A95C34 /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 567CE94128CB747200A95C34 /* RxCocoa */; };
2223
567E66D02438A6F80091B5D8 /* RxGRDB in Frameworks */ = {isa = PBXBuildFile; productRef = 567E66CF2438A6F80091B5D8 /* RxGRDB */; };
2324
56D6EA2F2438AB77000D55EF /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 56D6EA2E2438AB77000D55EF /* RxSwift */; };
2425
56D6EA322438ABAE000D55EF /* RxDataSources in Frameworks */ = {isa = PBXBuildFile; productRef = 56D6EA312438ABAE000D55EF /* RxDataSources */; };
@@ -100,6 +101,7 @@
100101
isa = PBXFrameworksBuildPhase;
101102
buildActionMask = 2147483647;
102103
files = (
104+
567CE94228CB747200A95C34 /* RxCocoa in Frameworks */,
103105
56D6EA352438ABD7000D55EF /* Action in Frameworks */,
104106
56D6EA442438AF90000D55EF /* GRDB in Frameworks */,
105107
56D6EA322438ABAE000D55EF /* RxDataSources in Frameworks */,
@@ -240,6 +242,7 @@
240242
56D6EA312438ABAE000D55EF /* RxDataSources */,
241243
56D6EA342438ABD7000D55EF /* Action */,
242244
56D6EA432438AF90000D55EF /* GRDB */,
245+
567CE94128CB747200A95C34 /* RxCocoa */,
243246
);
244247
productName = RxGRDBDemo;
245248
productReference = 56E1F9791F8101EE00793BFA /* RxGRDBDemo.app */;
@@ -629,12 +632,17 @@
629632
repositoryURL = "https://github.com/groue/GRDB.swift.git";
630633
requirement = {
631634
kind = upToNextMajorVersion;
632-
minimumVersion = 5.0.0;
635+
minimumVersion = 6.0.0;
633636
};
634637
};
635638
/* End XCRemoteSwiftPackageReference section */
636639

637640
/* Begin XCSwiftPackageProductDependency section */
641+
567CE94128CB747200A95C34 /* RxCocoa */ = {
642+
isa = XCSwiftPackageProductDependency;
643+
package = 56D6EA2D2438AB77000D55EF /* XCRemoteSwiftPackageReference "RxSwift" */;
644+
productName = RxCocoa;
645+
};
638646
567E66CF2438A6F80091B5D8 /* RxGRDB */ = {
639647
isa = XCSwiftPackageProductDependency;
640648
productName = RxGRDB;

Documentation/RxGRDBDemo/RxGRDBDemo/UI/PlayersViewController.swift

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import UIKit
22
import RxDataSources
33
import RxSwift
4+
import RxCocoa
45

56
/// An MVVM ViewController that displays PlayersViewModel
67
class PlayersViewController: UIViewController {
@@ -30,19 +31,19 @@ class PlayersViewController: UIViewController {
3031
return
3132
}
3233

33-
let barButtonItem = UIBarButtonItem(title: title, style: .plain, target: nil, action: nil)
34+
var barButtonItem = UIBarButtonItem(title: title, style: .plain, target: nil, action: nil)
3435
barButtonItem.rx.action = viewModel.toggleOrdering
3536
navigationItem.rightBarButtonItem = barButtonItem
3637
}
3738

3839
private func setupToolbar() {
39-
let deleteAllButtonItem = UIBarButtonItem(barButtonSystemItem: .trash, target: nil, action: nil)
40+
var deleteAllButtonItem = UIBarButtonItem(barButtonSystemItem: .trash, target: nil, action: nil)
4041
deleteAllButtonItem.rx.action = viewModel.deleteAll
4142

42-
let refreshButtonItem = UIBarButtonItem(barButtonSystemItem: .refresh, target: nil, action: nil)
43+
var refreshButtonItem = UIBarButtonItem(barButtonSystemItem: .refresh, target: nil, action: nil)
4344
refreshButtonItem.rx.action = viewModel.refresh
4445

45-
let stressTestButtonItem = UIBarButtonItem(title: "💣", style: .plain, target: nil, action: nil)
46+
var stressTestButtonItem = UIBarButtonItem(title: "💣", style: .plain, target: nil, action: nil)
4647
stressTestButtonItem.rx.action = viewModel.stressTest
4748

4849
toolbarItems = [

Documentation/RxGRDBDemo/RxGRDBDemoTests/AppDatabaseTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import GRDB
44
class AppDatabaseTests: XCTestCase {
55

66
func testDatabaseSchemaContainsPlayerTable() throws {
7-
let dbQueue = DatabaseQueue()
7+
let dbQueue = try DatabaseQueue()
88
try AppDatabase().setup(dbQueue)
99
try dbQueue.read { db in
1010
try XCTAssert(db.tableExists("player"))

Documentation/RxGRDBDemo/RxGRDBDemoTests/PlayerTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import GRDB
44
class PlayerTests: XCTestCase {
55

66
func testInsert() throws {
7-
let dbQueue = DatabaseQueue()
7+
let dbQueue = try DatabaseQueue()
88
try AppDatabase().setup(dbQueue)
99
try dbQueue.write { db in
1010
var player = Player(id: nil, name: "Arthur", score: 100)
@@ -14,7 +14,7 @@ class PlayerTests: XCTestCase {
1414
}
1515

1616
func testRoundtrip() throws {
17-
let dbQueue = DatabaseQueue()
17+
let dbQueue = try DatabaseQueue()
1818
try AppDatabase().setup(dbQueue)
1919
try dbQueue.write { db in
2020
var insertedPlayer = Player(id: 1, name: "Arthur", score: 100)
@@ -25,7 +25,7 @@ class PlayerTests: XCTestCase {
2525
}
2626

2727
func testOrderByScore() throws {
28-
let dbQueue = DatabaseQueue()
28+
let dbQueue = try DatabaseQueue()
2929
try AppDatabase().setup(dbQueue)
3030
var player1 = Player(id: 1, name: "Arthur", score: 100)
3131
var player2 = Player(id: 2, name: "Barbara", score: 200)
@@ -54,7 +54,7 @@ class PlayerTests: XCTestCase {
5454
}
5555

5656
func testOrderByName() throws {
57-
let dbQueue = DatabaseQueue()
57+
let dbQueue = try DatabaseQueue()
5858
try AppDatabase().setup(dbQueue)
5959
var player1 = Player(id: 1, name: "Arthur", score: 100)
6060
var player2 = Player(id: 2, name: "Barbara", score: 200)

Documentation/RxGRDBDemo/RxGRDBDemoTests/PlayersTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class PlayersTests: XCTestCase {
88
private func makeDatabase() throws -> DatabaseQueue {
99
// Players needs a database.
1010
// Setup an in-memory database, for fast access.
11-
let database = DatabaseQueue()
11+
let database = try DatabaseQueue()
1212
try AppDatabase().setup(database)
1313
return database
1414
}

Documentation/RxGRDBDemo/RxGRDBDemoTests/PlayersViewModelTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class PlayersViewModelTests: XCTestCase {
88
override func setUp() {
99
// PlayerViewModel needs a Current World.
1010
// Setup one with an in-memory database, for fast access.
11-
let dbQueue = DatabaseQueue()
11+
let dbQueue = try! DatabaseQueue()
1212
try! AppDatabase().setup(dbQueue)
1313
Current = World(database: { dbQueue })
1414
}

Package.swift

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
// swift-tools-version:5.2
1+
// swift-tools-version:5.7
22

33
import PackageDescription
44

55
let package = Package(
66
name: "RxGRDB",
77
platforms: [
88
.iOS(.v11),
9-
.macOS(.v10_10),
10-
.tvOS(.v9),
11-
.watchOS(.v2),
9+
.macOS(.v10_13),
10+
.tvOS(.v11),
11+
.watchOS(.v4),
1212
],
1313
products: [
1414
.library(name: "RxGRDB", targets: ["RxGRDB"]),
1515
],
1616
dependencies: [
17-
.package(name: "GRDB", url: "https://github.com/groue/GRDB.swift.git", .upToNextMajor(from: "5.12.0")),
17+
.package(url: "https://github.com/groue/GRDB.swift.git", .upToNextMajor(from: "6.0.0")),
1818
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.0.0"))
1919
],
2020
targets: [
2121
.target(
2222
name: "RxGRDB",
23-
dependencies: ["GRDB", "RxSwift"]),
23+
dependencies: [
24+
.product(name: "GRDB", package: "GRDB.swift"),
25+
.product(name: "RxSwift", package: "RxSwift"),
26+
]),
2427
.testTarget(
2528
name: "RxGRDBTests",
2629
dependencies: [
27-
"GRDB",
28-
"RxGRDB",
29-
.product(name: "RxBlocking", package: "RxSwift")])
30+
"RxGRDB",
31+
.product(name: "GRDB", package: "GRDB.swift"),
32+
.product(name: "RxBlocking", package: "RxSwift"),
33+
])
3034
],
3135
swiftLanguageVersions: [.v5]
3236
)

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
RxGRDB [![Swift 5.2](https://img.shields.io/badge/swift-5.2-orange.svg?style=flat)](https://developer.apple.com/swift/) [![Platforms](https://img.shields.io/cocoapods/p/RxGRDB.svg)](https://developer.apple.com/swift/) [![License](https://img.shields.io/github/license/RxSwiftCommunity/RxGRDB.svg?maxAge=2592000)](/LICENSE) [![Build Status](https://travis-ci.org/RxSwiftCommunity/RxGRDB.svg?branch=master)](https://travis-ci.org/RxSwiftCommunity/RxGRDB)
1+
RxGRDB [![Swift 5.7](https://img.shields.io/badge/swift-5.7-orange.svg?style=flat)](https://developer.apple.com/swift/) [![Platforms](https://img.shields.io/cocoapods/p/RxGRDB.svg)](https://developer.apple.com/swift/) [![License](https://img.shields.io/github/license/RxSwiftCommunity/RxGRDB.svg?maxAge=2592000)](/LICENSE) [![Build Status](https://travis-ci.org/RxSwiftCommunity/RxGRDB.svg?branch=master)](https://travis-ci.org/RxSwiftCommunity/RxGRDB)
22
======
33

44
### A set of extensions for [SQLite], [GRDB.swift], and [RxSwift]
55

66
**Latest release**: October 17, 2021 • version 2.1.0 • [Release Notes]
77

8-
**Requirements**: iOS 11.0+ / OSX 10.10+ / tvOS 9.0+ / watchOS 2.0+ • Swift 5.2+ / Xcode 11.4+
8+
**Requirements**: iOS 11.0+ / macOS 10.13+ / tvOS 11.0+ / watchOS 4.0+ Swift 5.7+ / Xcode 14+
99

1010
| Swift version | RxGRDB version |
1111
| -------------- | ----------------------------------------------------------------- |
12-
| **Swift 5.3+** | **v2.1.0**, [v2.1.0](http://github.com/RxSwiftCommunity/RxGRDB/tree/v2.1.0) |
12+
| Swift 5.3 | [v2.1.0](http://github.com/RxSwiftCommunity/RxGRDB/tree/v2.1.0) |
1313
| Swift 5.2 | [v2.0.0](http://github.com/RxSwiftCommunity/RxGRDB/tree/v2.0.0) |
1414
| Swift 5.1 | [v0.18.0](http://github.com/RxSwiftCommunity/RxGRDB/tree/v0.18.0) |
1515
| Swift 5.0 | [v0.18.0](http://github.com/RxSwiftCommunity/RxGRDB/tree/v0.18.0) |

RxGRDB.podspec

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ Pod::Spec.new do |s|
99
s.source = { :git => 'https://github.com/RxSwiftCommunity/RxGRDB.git', :tag => "v#{s.version}" }
1010
s.module_name = 'RxGRDB'
1111

12-
s.swift_versions = ['5.3', '5.4', '5.5']
12+
s.swift_versions = ['5.7']
1313
s.ios.deployment_target = '11.0'
14-
s.osx.deployment_target = '10.10'
15-
s.tvos.deployment_target = '9.0'
16-
s.watchos.deployment_target = '3.0'
14+
s.osx.deployment_target = '10.13'
15+
s.watchos.deployment_target = '4.0'
16+
s.tvos.deployment_target = '11.0'
1717

1818
s.dependency "RxSwift", "~> 6.0"
1919
s.default_subspec = 'default'
2020

2121
s.subspec 'default' do |ss|
2222
ss.source_files = 'Sources/RxGRDB/**/*.{swift}'
23-
ss.dependency "GRDB.swift", "~> 5.12"
23+
ss.dependency "GRDB.swift", "~> 6.0"
2424
end
2525

2626
s.subspec 'SQLCipher' do |ss|
2727
ss.source_files = 'Sources/RxGRDB/**/*.{swift}'
28-
ss.dependency "GRDB.swift/SQLCipher", "~> 5.12"
28+
ss.dependency "GRDB.swift/SQLCipher", "~> 6.0"
2929
ss.xcconfig = {
3030
'OTHER_SWIFT_FLAGS' => '$(inherited) -DSQLITE_HAS_CODEC -DUSING_SQLCIPHER',
3131
'OTHER_CFLAGS' => '$(inherited) -DSQLITE_HAS_CODEC -DUSING_SQLCIPHER',

Sources/RxGRDB/DatabaseReader+Rx.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension DatabaseReader {
1717
extension Reactive where Base: DatabaseReader {
1818
/// Returns a Single that asynchronously emits the fetched value.
1919
///
20-
/// let dbQueue = DatabaseQueue()
20+
/// let dbQueue = try DatabaseQueue()
2121
/// let players: Single<[Player]> = dbQueue.rx.read { db in
2222
/// try Player.fetchAll(db)
2323
/// }

Sources/RxGRDB/DatabaseRegionObservation+Rx.swift

+7-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extension GRDBReactive where Base == DatabaseRegionObservation {
1616
/// upon subscription. See [GRDB Concurrency Guide](https://github.com/groue/GRDB.swift/blob/master/README.md#concurrency)
1717
/// for more information.
1818
///
19-
/// let dbQueue = DatabaseQueue()
19+
/// let dbQueue = try DatabaseQueue()
2020
/// try dbQueue.write { db in
2121
/// try db.create(table: "player") { t in
2222
/// t.column("id", .integer).primaryKey()
@@ -54,16 +54,12 @@ extension GRDBReactive where Base == DatabaseRegionObservation {
5454
///
5555
/// - parameter writer: A DatabaseWriter (DatabaseQueue or DatabasePool).
5656
public func changes(in writer: DatabaseWriter) -> Observable<Database> {
57-
Observable.create { observer -> Disposable in
58-
do {
59-
let transactionObserver = try self.base.start(in: writer, onChange: observer.onNext)
60-
return Disposables.create {
61-
writer.remove(transactionObserver: transactionObserver)
62-
}
63-
} catch {
64-
observer.onError(error)
65-
return Disposables.create()
66-
}
57+
Observable.create { observer in
58+
let cancellable = self.base.start(
59+
in: writer,
60+
onError: observer.onError,
61+
onChange: observer.onNext)
62+
return Disposables.create(with: cancellable.cancel)
6763
}
6864
}
6965
}

Sources/RxGRDB/ValueObservation+Rx.swift

+12-11
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ extension ValueObservation {
99
/// :nodoc:
1010
public protocol _ValueObservationProtocol {
1111
associatedtype Reducer: _ValueReducer
12-
func start(
13-
in reader: DatabaseReader,
14-
scheduling scheduler: ValueObservationScheduler,
12+
func _start(
13+
in reader: GRDB.DatabaseReader,
14+
scheduling scheduler: GRDB.ValueObservationScheduler,
1515
onError: @escaping (Error) -> Void,
16-
onChange: @escaping (Reducer.Value) -> Void) -> DatabaseCancellable
16+
onChange: @escaping (Reducer.Value) -> Void)
17+
-> GRDB.DatabaseCancellable
1718
}
1819

1920
/// :nodoc:
20-
extension ValueObservation: _ValueObservationProtocol { }
21+
extension ValueObservation: _ValueObservationProtocol where Reducer: ValueReducer {
22+
public func _start(in reader: GRDB.DatabaseReader, scheduling scheduler: GRDB.ValueObservationScheduler, onError: @escaping (Error) -> Void, onChange: @escaping (Reducer.Value) -> Void) -> GRDB.DatabaseCancellable {
23+
start(in: reader, scheduling: scheduler, onError: onError, onChange: onChange)
24+
}
25+
}
2126

2227
extension GRDBReactive where Base: _ValueObservationProtocol {
2328
/// Creates an Observable which tracks changes in database values.
@@ -66,12 +71,8 @@ extension GRDBReactive where Base: _ValueObservationProtocol {
6671
scheduling scheduler: ValueObservationScheduler = .async(onQueue: .main))
6772
-> Observable<Base.Reducer.Value>
6873
{
69-
Observable.create { [weak reader] observer in
70-
guard let reader = reader else {
71-
return Disposables.create()
72-
}
73-
74-
let cancellable = self.base.start(
74+
Observable.create { observer in
75+
let cancellable = self.base._start(
7576
in: reader,
7677
scheduling: scheduler,
7778
onError: observer.onError,

Tests/RxGRDBTests/DatabaseReaderReadTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class DatabaseReaderReadTests : XCTestCase {
7878
}
7979

8080
try Test(test)
81-
.run { DatabaseQueue() }
81+
.run { try DatabaseQueue() }
8282
.runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
8383
.runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
8484
.runAtTemporaryDatabasePath { try DatabasePool(path: $0).makeSnapshot() }
@@ -214,7 +214,7 @@ class DatabaseReaderReadTests : XCTestCase {
214214
}
215215

216216
try Test(test)
217-
.run { DatabaseQueue() }
217+
.run { try DatabaseQueue() }
218218
.runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
219219
.runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
220220
.runAtTemporaryDatabasePath { try DatabasePool(path: $0).makeSnapshot() }

Tests/RxGRDBTests/DatabaseWriterWriteTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class DatabaseWriterWriteTests : XCTestCase {
9999
}
100100

101101
try Test(test)
102-
.run { DatabaseQueue() }
102+
.run { try DatabaseQueue() }
103103
.runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
104104
.runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
105105
}
@@ -279,7 +279,7 @@ class DatabaseWriterWriteTests : XCTestCase {
279279
}
280280

281281
try Test(test)
282-
.run { DatabaseQueue() }
282+
.run { try DatabaseQueue() }
283283
.runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
284284
.runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
285285
}
@@ -301,7 +301,7 @@ class DatabaseWriterWriteTests : XCTestCase {
301301
}
302302

303303
try Test(test)
304-
.run { DatabaseQueue() }
304+
.run { try DatabaseQueue() }
305305
.runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
306306
.runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
307307
}
@@ -353,7 +353,7 @@ class DatabaseWriterWriteTests : XCTestCase {
353353
}
354354

355355
try Test(test)
356-
.run { DatabaseQueue() }
356+
.run { try DatabaseQueue() }
357357
.runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
358358
.runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
359359
}

0 commit comments

Comments
 (0)