Is it possible to return Flow<List<Long>>
after Room
insert?
Something like this:
@Insert(onConflict = REPLACE)
suspend fun insert( notesModel: List<NotesModel>): Flow<List<Long>>
When I do it I get an exception:
error: Not sure how to handle insert method's return type.
AFAIK, you can't. The return type of @Insert
annotated functions could be Unit
, Long
, List<Long>
, or Array<Long>
.
Only @Query
annotated functions are able to return observable objects like LivaData
, Flow
, Single
, Flowable
, etc. Because the @Query
functions are designed to be able to reflect changes on db.
Here is a quote from official documentation:
If the @Insert method receives only 1 parameter, it can return a long, which is the new rowId for the inserted item. If the parameter is an array or a collection, it should return long[] or List instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With