Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to return Flow<List<Long>> after Room insert?

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.

like image 787
Denis Fedak Avatar asked Oct 19 '25 08:10

Denis Fedak


1 Answers

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.

like image 55
aminography Avatar answered Oct 21 '25 23:10

aminography



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!