Fixed
Status Update
Comments
[Deleted User] <[Deleted User]> #2
+1, but Deferred does not solve the Observer problem that Rx and LiveData do, so I guess Google should implement Channels instead of LiveData which is actually a Kotlin Coroutine counterpart. Looking forward to this as I've decided not to use RxJava in most of future projects due to Kotlin Coroutines..
fl...@google.com <fl...@google.com>
da...@google.com <da...@google.com>
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit e78cceffeac28f0028342990c1391c640edf453c
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Wed Nov 28 12:40:24 2018
Room Support for Coroutines
This change allows users to define suspend functions in DAOs with
@Query, @Insert, @Update and @Delete. The new artifact room-coroutine
defines a helper classes for supporting the feature.
Bug: 69474692
Test: ./gradlew room:integration-tests:kotlintestapp:cC
Change-Id: Id73a6b845df3f21f99d14cb6980130dcf3885c81
M buildSrc/src/main/kotlin/androidx/build/PublishDocsRules.kt
A room/compiler/src/main/kotlin/androidx/room/ext/KotlinMetadataElement.kt
D room/compiler/src/main/kotlin/androidx/room/ext/KotlinMetadataProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/ext/element_ext.kt
M room/compiler/src/main/kotlin/androidx/room/ext/javapoet_ext.kt
M room/compiler/src/main/kotlin/androidx/room/processor/DeletionMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/InsertionMethodProcessor.kt
A room/compiler/src/main/kotlin/androidx/room/processor/MethodProcessorDelegate.kt
M room/compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/ProcessorErrors.kt
M room/compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/RawQueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/ShortcutMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/UpdateMethodProcessor.kt
A room/compiler/src/main/kotlin/androidx/room/solver/query/result/CoroutineResultBinder.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
A room/compiler/src/main/kotlin/androidx/room/solver/shortcut/binder/CoroutineDeleteOrUpdateMethodBinder.kt
A room/compiler/src/main/kotlin/androidx/room/solver/shortcut/binder/CoroutineInsertMethodBinder.kt
M room/compiler/src/main/kotlin/androidx/room/solver/shortcut/result/DeleteOrUpdateMethodAdapter.kt
M room/compiler/src/main/kotlin/androidx/room/solver/shortcut/result/InsertMethodAdapter.kt
M room/compiler/src/main/kotlin/androidx/room/vo/RelationCollector.kt
M room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
A room/coroutines/build.gradle
A room/coroutines/src/main/AndroidManifest.xml
A room/coroutines/src/main/java/androidx/room/CoroutinesRoom.kt
M room/integration-tests/kotlintestapp/build.gradle
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/BooksDaoTest.kt
A room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/SuspendRoomDispatcherTest.kt
M settings.gradle
https://android-review.googlesource.com/833705
https://goto.google.com/android-sha1/e78cceffeac28f0028342990c1391c640edf453c
Branch: androidx-master-dev
commit e78cceffeac28f0028342990c1391c640edf453c
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Wed Nov 28 12:40:24 2018
Room Support for Coroutines
This change allows users to define suspend functions in DAOs with
@Query, @Insert, @Update and @Delete. The new artifact room-coroutine
defines a helper classes for supporting the feature.
Bug: 69474692
Test: ./gradlew room:integration-tests:kotlintestapp:cC
Change-Id: Id73a6b845df3f21f99d14cb6980130dcf3885c81
M buildSrc/src/main/kotlin/androidx/build/PublishDocsRules.kt
A room/compiler/src/main/kotlin/androidx/room/ext/KotlinMetadataElement.kt
D room/compiler/src/main/kotlin/androidx/room/ext/KotlinMetadataProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/ext/element_ext.kt
M room/compiler/src/main/kotlin/androidx/room/ext/javapoet_ext.kt
M room/compiler/src/main/kotlin/androidx/room/processor/DeletionMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/InsertionMethodProcessor.kt
A room/compiler/src/main/kotlin/androidx/room/processor/MethodProcessorDelegate.kt
M room/compiler/src/main/kotlin/androidx/room/processor/PojoProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/ProcessorErrors.kt
M room/compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/RawQueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/ShortcutMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/processor/UpdateMethodProcessor.kt
A room/compiler/src/main/kotlin/androidx/room/solver/query/result/CoroutineResultBinder.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
A room/compiler/src/main/kotlin/androidx/room/solver/shortcut/binder/CoroutineDeleteOrUpdateMethodBinder.kt
A room/compiler/src/main/kotlin/androidx/room/solver/shortcut/binder/CoroutineInsertMethodBinder.kt
M room/compiler/src/main/kotlin/androidx/room/solver/shortcut/result/DeleteOrUpdateMethodAdapter.kt
M room/compiler/src/main/kotlin/androidx/room/solver/shortcut/result/InsertMethodAdapter.kt
M room/compiler/src/main/kotlin/androidx/room/vo/RelationCollector.kt
M room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
A room/coroutines/build.gradle
A room/coroutines/src/main/AndroidManifest.xml
A room/coroutines/src/main/java/androidx/room/CoroutinesRoom.kt
M room/integration-tests/kotlintestapp/build.gradle
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/dao/BooksDao.kt
M room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/BooksDaoTest.kt
A room/integration-tests/kotlintestapp/src/androidTest/java/androidx/room/integration/kotlintestapp/test/SuspendRoomDispatcherTest.kt
M settings.gradle
[Deleted User] <[Deleted User]> #4
So do you support any Coroutine "observables" like channels? Or these are just one-off suspending calls?
da...@google.com <da...@google.com> #5
For now we'll be just supporting one-off suspend functions in Room 2.1.0-alpha03. Coroutines stream functionality with channels is still a work in progress.
ma...@marcardar.com <ma...@marcardar.com> #6
Relating to the original request, how about allowing a return type of Deferred<LiveData<T>> which suspends until LiveData<T>'s value has been set the first time?
je...@gmail.com <je...@gmail.com> #7
I just tested out Room 2.1.0-alpha03 and added suspend to all of my functions.... there appears to be an issue with functions that use @Query() and UPDATE and DELETE queries. Examples:
Code Example 1:
@Query("DELETE FROM individual")
suspend fun deleteAll()
Error:
Deletion methods must either return void or return int (the number of deleted rows).
Code Example 2:
@Query("UPDATE individual SET firstName = :firstName WHERE id = :id")
suspend fun updateFirstName(id: Long, firstName: String)
Error:
Not sure how to convert a Cursor to this method's return type (kotlin.Unit).
Code Example 1:
@Query("DELETE FROM individual")
suspend fun deleteAll()
Error:
Deletion methods must either return void or return int (the number of deleted rows).
Code Example 2:
@Query("UPDATE individual SET firstName = :firstName WHERE id = :id")
suspend fun updateFirstName(id: Long, firstName: String)
Error:
Not sure how to convert a Cursor to this method's return type (kotlin.Unit).
da...@google.com <da...@google.com> #8
Async return types with @Query that perform UPDATE, DELETE or INSERT are not yet supported. This also applies to coroutines. We are actively working on adding this for the next alpha of 2.1.0. Subscribe to the bug for updates: https://issuetracker.google.com/issues/120227284
[Deleted User] <[Deleted User]> #9
Hello.
Any updates on returning Channel<T> from DAO?
Will contributions be accepted for that feature?
Any updates on returning Channel<T> from DAO?
Will contributions be accepted for that feature?
yb...@google.com <yb...@google.com> #10
Channels are experimental right now so we probably want to wait until it is stable.
cr...@shou.tv <cr...@shou.tv> #11
Channels +1
da...@google.com <da...@google.com> #12
Marking as fix since core coroutines are supported in 2.1, in the mean time we'll keep an eye on the Channels API to potentially support it once its upgraded out of experimental. https://issuetracker.google.com/issues/127328278
pi...@gmail.com <pi...@gmail.com> #13
Is it expected that we still have to ensure that suspended functions aren't dispatched from the main thread?
The first call (eg `final SupportSQLiteStatement _stmt = __preparedStmtOfDeleteAll.acquire();`) is not wrapped in a callable and can't be done on the ui thread, so we still have to wrap suspensions with our own context.
The first call (eg `final SupportSQLiteStatement _stmt = __preparedStmtOfDeleteAll.acquire();`) is not wrapped in a callable and can't be done on the ui thread, so we still have to wrap suspensions with our own context.
ai...@gmail.com <ai...@gmail.com> #14
Kotlinx.coroutines 1.2 released with cold stream abstraction Flow:
https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html
It's in "preview" status, but maybe we also could expect some experimental version of Room with Flow support for observable requests
It's in "preview" status, but maybe we also could expect some experimental version of Room with Flow support for observable requests
Description
Version used: 1.0.0
Room currently supports RxJava and LiveData, but it would be great to also have support for Kotlin's Coroutines.
In a basic implementation this could be achieved with supporting the following types:
- Query: Deferred<T>
- Insert: Job or Deferred<Long>
- Delete: Job or Deferred<Int>
- Update: Job or Deferred<Int>
What could be really awesome though would be implementing support for the `suspend` keyword, as the developer would be able to write just:
```
@Query("SELECT * FROM ITEMS")
suspend fun getItems(): List<Item>
```
I understand this might be tricky to implement on your side though, since a suspend function has got a continuation parameter and that might be an issue with the way Room currently works.