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

Asynchronous database access #55

Merged
merged 50 commits into from
Jun 22, 2019
Merged

Conversation

groue
Copy link
Collaborator

@groue groue commented Jun 15, 2019

This PR brings support for reactive asynchronous reads and writes:

let dbQueue: DatabaseQueue = ...

// Async write
let write: Completable = dbQueue.rx.write { db in
    try Player(...).insert(db)
}

let newPlayerCount: Single<Int> = dbQueue.rx.writeAndReturn { db in
    try Player(...).insert(db)
    return try Player.fetchCount(db)
}

// Async read
let players: Single<[Player]> = dbQueue.rx.read { db in
    try Player.fetchAll(db)
}

Advanced scheduling for DatabasePool:

// Async write + read
let newPlayerCount: Single<Int> = dbPool.rx.write(
    updates: { db in try Player(...).insert(db) },
    thenRead: { db in try Player.fetchCount(db) })

Breaking changes

The observation methods have been renamed from fetch... to observe...:

-Player.all().rx.fetchOne(in: dbQueue)
-Player.all().rx.fetchAll(in: dbQueue)
-Player.all().rx.fetchCount(in: dbQueue)
+Player.all().rx.observeFirst(in: dbQueue)
+Player.all().rx.observeAll(in: dbQueue)
+Player.all().rx.observeCount(in: dbQueue)

The way to provide a specific scheduler to a value observable has changed:

-Player.all().rx.fetchAll(in: dbQueue, scheduler: MainScheduler.asyncInstance)
+Player.all().rx.observeAll(in: dbQueue, observeOn: MainScheduler.asyncInstance)

@groue groue mentioned this pull request Jun 18, 2019
10 tasks
@groue
Copy link
Collaborator Author

groue commented Jun 20, 2019

  • rename writeCompletable to write, and write to writeAndReturn (like catchErrorJustReturn)

@groue groue marked this pull request as ready for review June 22, 2019 07:15
@RxSwiftCommunity RxSwiftCommunity deleted a comment from rxswiftcommunity bot Jun 22, 2019
@groue groue merged commit 529350e into RxSwiftCommunity:develop Jun 22, 2019
@groue groue deleted the dev/async branch June 22, 2019 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant