Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRDB3 #32

Merged
merged 43 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
02fb998
Support for GRDB 3.0
hartbit Mar 12, 2018
1e1531f
Solve the PAT problem at GRDB level
groue Mar 13, 2018
97103b1
Merge branch 'master' into GRDB3
groue Mar 26, 2018
4ae6f26
Update RxGRDBDemo for GRDB 3.0
groue Mar 26, 2018
049911b
Support for latest GRDB3-Associations
groue Apr 29, 2018
98c3666
Fix tests that were failing because of https://github.com/groue/GRDB.…
groue Apr 29, 2018
edf8b4f
Xcode 9.3+, Swift 4.1+ required
groue Apr 29, 2018
4d3d1b3
Introduce DatabaseRegionConvertible
groue May 4, 2018
e10377d
Cleanup and inline documentation
groue May 5, 2018
6f55537
Hide FetchToken
groue May 5, 2018
58e4ff5
Fix RXGRDBDemo
groue May 5, 2018
2e10a06
RXGRDBDemo modernization
groue May 5, 2018
e833405
CHANGELOG.md
groue May 5, 2018
86bfeba
Documentation
groue May 5, 2018
85a72bf
Documentation
groue May 5, 2018
eb48089
Documentation
groue May 5, 2018
2c97f1e
Documentation
groue May 5, 2018
604e030
Documentation
groue May 5, 2018
9bffc7d
Documentation
groue May 5, 2018
6a122b5
Merge branch 'develop' into GRDB3
groue May 6, 2018
7a10ea9
Documentation
groue May 6, 2018
021a2aa
Documentation
groue May 6, 2018
d3e5641
Documentation
groue May 6, 2018
301b1f7
Documentation
groue May 6, 2018
635a46b
Documentation
groue May 6, 2018
4678f54
Documentation
groue May 6, 2018
1169c72
Documentation
groue May 6, 2018
2f9d16c
Documentation
groue May 6, 2018
280ada2
Documentation
groue May 6, 2018
12c409f
Documentation
groue May 6, 2018
dae35ff
playground update
groue May 6, 2018
35fc5b2
Test for DatabaseRegion.fullDatabase observation
groue May 6, 2018
c981520
Documentation
groue May 6, 2018
8ed108c
Use GRDB from the GRDB3 branch
groue May 6, 2018
fb16811
Update requirements
groue May 6, 2018
ecda5c2
Improve PrimaryKeyDiffScanner documentation
groue May 7, 2018
7d77cac
Fix typo
groue May 7, 2018
577e429
Update README with modern GRDB 3 APIs
groue May 7, 2018
878b58b
Use the new orderedByPrimaryKey method
groue Jun 6, 2018
da18843
Fix typo
groue Jun 6, 2018
eac74fd
minor
groue Jun 6, 2018
0c7c45f
Makefile: support for Xcode 9.4
groue Jun 7, 2018
a98ab1a
v0.11.0
groue Jun 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
4.1
20 changes: 10 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,36 @@ jobs:
###########################################
## Test RxGRDB

# Test RxGRDBmacOS (Xcode 9.1)
# Test RxGRDBmacOS (Xcode 9.3)
- stage: Test RxGRDB
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.1
osx_image: xcode9.3
env:
- TID=RxGRDBOSX (Xcode 9.1, macOS)
- TID=RxGRDBOSX (Xcode 9.3, macOS)
script: make test_framework_RxGRDBmacOS

# Test RxGRDBiOS (Xcode 9.1, iOS <MAXIMUM VERSION>)
# Test RxGRDBiOS (Xcode 9.3, iOS <MAXIMUM VERSION>)
- stage: Test RxGRDB
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.1
osx_image: xcode9.3
env:
- TID=RxGRDBiOS (Xcode 9.1, iOS <MAX>)
- TID=RxGRDBiOS (Xcode 9.3, iOS <MAX>)
script: make test_framework_RxGRDBiOS_maxTarget

# Test RxGRDBiOS (Xcode 9.1, iOS <MINIMUM VERSION>))
# Test RxGRDBiOS (Xcode 9.3, iOS <MINIMUM VERSION>))
- stage: Test RxGRDB
gemfile: .ci/gemfiles/Gemfile.travis
osx_image: xcode9.1
osx_image: xcode9.3
env:
- TID=RxGRDBiOS (Xcode 9.1, iOS <MIN>)
- TID=RxGRDBiOS (Xcode 9.3, iOS <MIN>)
script: make test_framework_RxGRDBiOS_minTarget

###########################################
## Test Installation Methods

# Cocoapods Lint
- stage: Test Installation
osx_image: xcode9.1
osx_image: xcode9.3
install:
- gem install cocoapods # Since Travis is not always on latest version
env:
Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
Release Notes
=============

## 0.11.0

Released June 7, 2018 &bull; [diff](https://github.com/RxSwiftCommunity/RxGRDB/compare/v0.10.0...v0.11.0)

### New

- Support for GRDB 3.0
- The new DatabaseRegionConvertible protocol allows better request encapsulation ([documentation](README.md#databaseregionconvertible-protocol))

### Breaking Changes

- "Fetch tokens" and the `mapFetch` operator were ill-advised, and have been removed. Now please use the new `DatabaseWriter.fetch(from:startImmediately:scheduler:values:)` method instead, which produces exactly the same observable:

```diff
// Old way
-let values = dbQueue.rx
- .fetchTokens(in: [request, ...])
- .mapFetch { db in
- try fetchResults(db)
- }

// New way
+let values = dbQueue.rx.fetch(from: [request, ...]) { db in
+ try fetchResults(db)
+}
```


## 0.10.0

Released March 26, 2018 &bull; [diff](https://github.com/RxSwiftCommunity/RxGRDB/compare/v0.9.0...v0.10.0)
Expand Down
65 changes: 42 additions & 23 deletions Documentation/Playgrounds/RxGRDB.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
//: Playground - noun: a place where people can play

//: To run this playground:
//:
//: - Run `pod install` in the terminal
//: - Open RxGRDB.xcworkspace
//: - Select the RxGRDBmacOS scheme: menu Product > Scheme > RxGRDBmacOS
//: - Build: menu Product > Build
//: - Select the playground in the Playgrounds Group
//: - Run the playground
import GRDB
import RxGRDB
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true

//: Create a database:
let dbQueue = DatabaseQueue()
try dbQueue.inDatabase { db in
try db.create(table: "persons") { t in
t.column("id", .integer).primaryKey()
t.column("name", .text)
try dbQueue.write { db in
try db.create(table: "player") { t in
t.autoIncrementedPrimaryKey("id")
t.column("name", .text).notNull()
t.column("score", .integer).notNull()
}
}

//: Define a Player record:
struct Player: Codable, FetchableRecord, MutablePersistableRecord {
var id: Int64?
var name: String
var score: Int

static let databaseTableName = "player"
mutating func didInsert(with rowID: Int64, for column: String?) {
id = rowID
}
}

let request = SQLRequest("SELECT * FROM persons")
request.rx
.changes(in: dbQueue)
.subscribe(onNext: { db in
let count = try! request.fetchCount(db)
print("Number of persons: \(count)")
//: Track the number of players:
Player.all().rx
.fetchCount(in: dbQueue)
.subscribe(onNext: { count in
print("Number of players: \(count)")
})
// Prints "Number of persons: 0"

try dbQueue.inDatabase { db in
try db.execute("INSERT INTO persons (name) VALUES (?)", arguments: ["Arthur"])
// Prints "Number of persons: 1"
try db.execute("INSERT INTO persons (name) VALUES (?)", arguments: ["Barbara"])
// Prints "Number of persons: 2"
//: Modify the database:
try dbQueue.write { db in
var player = Player(id: nil, name: "Arthur", score: 100)
try player.insert(db)
}

try dbQueue.inTransaction { db in
try db.execute("INSERT INTO persons (name) VALUES (?)", arguments: ["Craig"])
try db.execute("INSERT INTO persons (name) VALUES (?)", arguments: ["David"])
return .commit
try dbQueue.write { db in
var player = Player(id: nil, name: "Barbara", score: 250)
try player.insert(db)
player = Player(id: nil, name: "Craig", score: 150)
try player.insert(db)
}
// Prints "Number of persons: 4"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos'>
<playground version='5.0' target-platform='macos' display-mode='rendered'>
<timeline fileName='timeline.xctimeline'/>
</playground>
16 changes: 0 additions & 16 deletions Documentation/RxGRDBDemo/RxGRDBDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
56E1F9771F8101EE00793BFA /* Resources */,
569E8501200A5C720028D1EC /* Embed Frameworks */,
B0756943CADD6226BB774BD5 /* [CP] Embed Pods Frameworks */,
141918CC9EFD532C181264F0 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -188,21 +187,6 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
141918CC9EFD532C181264F0 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/../../Pods/Target Support Files/Pods-RxGRDBDemo/Pods-RxGRDBDemo-resources.sh\"\n";
showEnvVarsInLog = 0;
};
95963AD3C11B669F6A76FFF0 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
8 changes: 4 additions & 4 deletions Documentation/RxGRDBDemo/RxGRDBDemo/AppDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ struct AppDatabase {
var migrator = DatabaseMigrator()

migrator.registerMigration("v1.0") { db in
try db.create(table: "players") { t in
t.column("id", .integer).primaryKey()
try db.create(table: "player") { t in
t.autoIncrementedPrimaryKey("id")
t.column("name", .text).notNull().collate(.localizedCaseInsensitiveCompare)
t.column("score", .integer).notNull()
}

try db.create(table: "places") { t in
t.column("id", .integer).primaryKey()
try db.create(table: "place") { t in
t.autoIncrementedPrimaryKey("id")
t.column("latitude", .double).notNull()
t.column("longitude", .double).notNull()
}
Expand Down
20 changes: 9 additions & 11 deletions Documentation/RxGRDBDemo/RxGRDBDemo/Place.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,25 @@ struct Place: Codable {
}
}

// Define colums so that we can build GRDB requests
extension Place {
enum Columns {
static let id = Column("id")
}
}

// Adopt RowConvertible so that we can fetch places from the database.
// Implementation is automatically derived from Codable.
extension Place: RowConvertible { }
extension Place: FetchableRecord { }

// Adopt MutablePersistable so that we can create/update/delete places in the database.
// Implementation is partially derived from Codable.
extension Place: MutablePersistable {
static let databaseTableName = "places"
extension Place: MutablePersistableRecord {
static let databaseTableName = "place"

enum Columns: String, ColumnExpression {
case id, latitude, longitude
}

mutating func didInsert(with rowID: Int64, for column: String?) {
id = rowID
}
}

// Support for place randomization
// Place randomization
extension Place {
static func randomCoordinate() -> CLLocationCoordinate2D {
let paris = CLLocationCoordinate2D(latitude: 48.8534100, longitude: 2.3488000)
Expand Down
9 changes: 4 additions & 5 deletions Documentation/RxGRDBDemo/RxGRDBDemo/PlaceAnnotation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@ final class PlaceAnnotation: NSObject, MKAnnotation {
}
}

// Have PlaceAnnotation adopt RowConvertible, Persistable, and Diffable, so
// that it can feed the `primaryKeySortedDiff` observable.
// Have PlaceAnnotation adopt FetchableRecord and PersistableRecord, so
// that it can feed PrimaryKeyDiffScanner:

extension PlaceAnnotation: RowConvertible {
extension PlaceAnnotation: FetchableRecord {
convenience init(row: Row) {
self.init(place: Place(row: row))
}
}

extension PlaceAnnotation: Persistable {
extension PlaceAnnotation: PersistableRecord {
static let databaseTableName = Place.databaseTableName

func encode(to container: inout PersistenceContainer) {
place.encode(to: &container)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ extension PlacesViewController {
}

@IBAction func stressTest() {
DispatchQueue.concurrentPerform(iterations: 50) { _ in
self.refresh()
for _ in 0..<50 {
DispatchQueue.global().async {
self.refresh()
}
}
}
}
Expand All @@ -89,7 +91,7 @@ extension PlacesViewController: MKMapViewDelegate {
// To efficiently update the map view as database content changes, we
// use PrimaryKeyDiffScanner. It requires the tracked database request
// to be sorted by primary key:
let placeAnnotations = PlaceAnnotation.order(Place.Columns.id)
let placeAnnotations = PlaceAnnotation.orderByPrimaryKey()

let diffScanner = try! dbPool.read { db in
try PrimaryKeyDiffScanner(
Expand Down
21 changes: 9 additions & 12 deletions Documentation/RxGRDBDemo/RxGRDBDemo/Player.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@ struct Player: Codable {
var score: Int
}

// Define colums so that we can build GRDB requests
extension Player {
enum Columns {
static let name = Column("name")
static let score = Column("score")
}
}

// Adopt RowConvertible so that we can fetch players from the database.
// Implementation is automatically derived from Codable.
extension Player: RowConvertible { }
extension Player: FetchableRecord { }

// Adopt MutablePersistable so that we can create/update/delete players in the database.
// Implementation is partially derived from Codable.
extension Player: MutablePersistable {
static let databaseTableName = "players"
extension Player: MutablePersistableRecord {
static let databaseTableName = "player"

enum Columns: String, ColumnExpression {
case id, name, score
}

mutating func didInsert(with rowID: Int64, for column: String?) {
id = rowID
}
}

// Support for player randomization
// Player randomization
extension Player {
private static let names = ["Arthur", "Anita", "Barbara", "Bernard", "Craig", "Chiara", "David", "Dean", "Éric", "Elena", "Fatima", "Frederik", "Gilbert", "Georgette", "Henriette", "Hassan", "Ignacio", "Irene", "Julie", "Jack", "Karl", "Kristel", "Louis", "Liz", "Masashi", "Mary", "Noam", "Nicole", "Ophelie", "Oleg", "Pascal", "Patricia", "Quentin", "Quinn", "Raoul", "Rachel", "Stephan", "Susie", "Tristan", "Tatiana", "Ursule", "Urbain", "Victor", "Violette", "Wilfried", "Wilhelmina", "Yvon", "Yann", "Zazie", "Zoé"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ extension PlayersViewController {
}

@IBAction func stressTest() {
DispatchQueue.concurrentPerform(iterations: 50) { _ in
self.refresh()
for _ in 0..<50 {
DispatchQueue.global().async {
self.refresh()
}
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ XCODEBUILD := set -o pipefail && $(shell command -v xcodebuild)
XCODEVERSION_FULL := $(word 2, $(shell xcodebuild -version))
XCODEVERSION_MAJOR := $(shell xcodebuild -version 2>&1 | grep Xcode | cut -d' ' -f2 | cut -d'.' -f1)
XCODEVERSION_MINOR := $(shell xcodebuild -version 2>&1 | grep Xcode | cut -d' ' -f2 | cut -d'.' -f2)
XCODEVERSION_PATCH := $(shell xcodebuild -version 2>&1 | grep Xcode | cut -d' ' -f2 | cut -d'.' -f3)

# The Xcode Version, containing only the "MAJOR.MINOR" (ex. "8.3" for Xcode 8.3, 8.3.1, etc.)
XCODEVERSION := $(XCODEVERSION_MAJOR).$(XCODEVERSION_MINOR)
Expand All @@ -33,17 +34,15 @@ XCPRETTY_PATH := $(shell command -v xcpretty 2> /dev/null)
# xcodebuild actions to run test targets
TEST_ACTIONS = clean build build-for-testing test-without-building

# xcodebuild destination to run tests on iOS 8.1 (requires a pre-installed simulator)
MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 4s,OS=8.1"

ifeq ($(XCODEVERSION),9.2)
MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.2"
else ifeq ($(XCODEVERSION),9.1)
MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.1"
else ifeq ($(XCODEVERSION),9.0)
MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.0"
# When adding support for an Xcode version, look for available devices with `instruments -s devices`
ifeq ($(XCODEVERSION),9.4)
MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.4"
MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 4s,OS=9.0"
else ifeq ($(XCODEVERSION),9.3)
MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 8,OS=11.3"
MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 4s,OS=9.0"
else
# Xcode < 9.0 is not supported
# Swift 4.1 required: Xcode < 9.3 is not supported
endif

# If xcpretty is available, use it for xcodebuild output
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ workspace 'RxGRDB.xcworkspace'

def common
pod 'RxSwift', '~> 4.0'
pod 'GRDB.swift', '~> 2.6'
pod 'GRDB.swift', '~> 3.0'
end

target 'RxGRDBiOS' do
Expand Down
Loading