android-room

How to return a Rx Single transaction using Room Db?

故事扮演 提交于 2020-06-16 02:00:02
问题 Suppose there is a Dao class with the following two methods: 1) delete(items: List<Item>): Completable 2) insert(items: List< Item >): Single<List<Long>> How can I chain them into a @transaction method in Dao class starting with ‘delete method’ and then returning ‘insert method’ result? I want to have a method with a signature like this: @Transaction fun deleteAndInsert(): Single<List<Long> > { ... } 回答1: I'm assuming your main goal is to have the return type of deleteAndInsert() as Single .

How to return a Rx Single transaction using Room Db?

♀尐吖头ヾ 提交于 2020-06-16 01:56:08
问题 Suppose there is a Dao class with the following two methods: 1) delete(items: List<Item>): Completable 2) insert(items: List< Item >): Single<List<Long>> How can I chain them into a @transaction method in Dao class starting with ‘delete method’ and then returning ‘insert method’ result? I want to have a method with a signature like this: @Transaction fun deleteAndInsert(): Single<List<Long> > { ... } 回答1: I'm assuming your main goal is to have the return type of deleteAndInsert() as Single .

Android Room - Usage of foreign key in query

瘦欲@ 提交于 2020-06-12 19:56:25
问题 I have a Component which contains a foreign key coming from Component_category My purpose is that a component list will be filtered by the selected component category. Both classes are as followed: Component @Entity(tableName = "component_table", foreignKeys = { @ForeignKey( entity = Rack.class, parentColumns = "rack_id", childColumns = "component_id", onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.CASCADE ), @ForeignKey( entity = ComponentCat.class, parentColumns = "component_cat_id",

Android Room - Usage of foreign key in query

天涯浪子 提交于 2020-06-12 19:46:09
问题 I have a Component which contains a foreign key coming from Component_category My purpose is that a component list will be filtered by the selected component category. Both classes are as followed: Component @Entity(tableName = "component_table", foreignKeys = { @ForeignKey( entity = Rack.class, parentColumns = "rack_id", childColumns = "component_id", onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.CASCADE ), @ForeignKey( entity = ComponentCat.class, parentColumns = "component_cat_id",

How do I delete the file of an Android Room database?

限于喜欢 提交于 2020-06-12 07:17:19
问题 I have implemented a room database which is distributed from a resource file using SQLiteAssetHelper the first time the app is started. The database contains game status data so if the Player wants to start all over again, I want to copy again the database file from the resource and overwrite the "local/internal" file. So my idea was to delete the interal db-file so that SQLiteAssetHelper will copy the Initial database from the resource again. Thank you! Kev 回答1: Here's a working example:

How to read data and listen to changes from Room database in a Service?

时光怂恿深爱的人放手 提交于 2020-06-12 03:00:13
问题 i am storing user information in a local room database. In activities and fragments I use AndroidViewModel and LiveData to listen to changes made to the database and update the UI. Now I want to analyze all of the past user data to give recommendations for future decisions. My recommendations change on every change to the database made by the user so I need to update my reommendations frequently while doing the same calculations over and over again. I was thinking about starting a service on

How to read data and listen to changes from Room database in a Service?

徘徊边缘 提交于 2020-06-12 03:00:06
问题 i am storing user information in a local room database. In activities and fragments I use AndroidViewModel and LiveData to listen to changes made to the database and update the UI. Now I want to analyze all of the past user data to give recommendations for future decisions. My recommendations change on every change to the database made by the user so I need to update my reommendations frequently while doing the same calculations over and over again. I was thinking about starting a service on

Room: Receiving error when using @Transaction

烈酒焚心 提交于 2020-06-10 07:38:08
问题 I'm have a method annotated with @Transaction in my DAO class, which is causing the following error: A DAO method can be annotated with only one of the following:Insert,Delete,Query,Update Here's my class: @Dao interface Dao { @Insert(onConflict = REPLACE) fun insertList(chacaras: List<String>) @Query("SELECT * FROM chacara WHERE cityId = :cityId") fun getListOfCity(cityId: String): LiveData<List<String>> @Delete fun deleteList(chacaraList: List<String>) @Transaction fun updateList(list: List

Remove room database on app uninstall

大憨熊 提交于 2020-06-10 02:46:47
问题 I am making an app and I am using Android Room Persistence Library to handle my database layer. Room Library works like charm and everything is fine with it. But I want the database that room creates to be removed when the user uninstall the app. I tried uninstalling the app and then installed again, but somehow the database was still there and app was able to get the old data from it. I thought maybe because my app data backup is set to auto in the settings and android is backing it up on

How to join multiple instances of same object in Android Room?

感情迁移 提交于 2020-06-08 17:27:12
问题 NOTE: I cannot use relation as we had performance issue which is not reproduced on direct join query. Until I added target user and from group user and corresponding LEFT JOIN chat_user ON chat_user.chat_user_id = message_item.messages_target_user LEFT JOIN chat_user ON chat_user.chat_user_id = message_item.messages_from_group_user It worked well. But after addition, I can not figure out how to make those prefixes map in the query. class ReadMessageEntity( @Embedded var message: MessageEntity