android-room

How to do a single row query with Android Room

ⅰ亾dé卋堺 提交于 2021-02-17 21:31:10
问题 How do I make a single row query with Android Room with RxJava? I am able to query for List of items, no issues. Here, I want to find if a specific row exists. According to the docs, looks like I can return Single and check for EmptyResultSetException exception if no row exists. I can have something like: @Query("SELECT * FROM Users WHERE userId = :id LIMIT 1") Single<User> findByUserId(String userId); How do I use this call? Looks like there is some onError / onSuccess but cannot find those

How to do a single row query with Android Room

陌路散爱 提交于 2021-02-17 21:30:19
问题 How do I make a single row query with Android Room with RxJava? I am able to query for List of items, no issues. Here, I want to find if a specific row exists. According to the docs, looks like I can return Single and check for EmptyResultSetException exception if no row exists. I can have something like: @Query("SELECT * FROM Users WHERE userId = :id LIMIT 1") Single<User> findByUserId(String userId); How do I use this call? Looks like there is some onError / onSuccess but cannot find those

Is there a way to control the order of child entity, when using one-to-many relationhips?

北慕城南 提交于 2021-02-16 16:27:09
问题 According to https://developer.android.com/training/data-storage/room/relationships We can have one-to-many relationships public class UserWithPlaylists { @Embedded public User user; @Relation( parentColumn = "userId", entityColumn = "userCreatorId" ) public List<Playlist> playlists; } @Transaction @Query("SELECT * FROM User") public List<UserWithPlaylists> getUsersWithPlaylists(); In both entity User and Playlist , we have added a column named sort_key The purpose is, when we perform query,

I can auto increment id in room database but when refresh database it's shows double

蹲街弑〆低调 提交于 2021-02-13 12:58:47
问题 In my app firstly i am fetching data from server using retrofit then it's saved in room database table then it shows in recyclerview but when i using a id as a primary key it's show only one data then this id i annotat autoGenerate = true then it's show all data which i put in server but when i reopen my app,it's show double data(this mean firstly i have 3 data in server,this app show 3 data but when i reopen or refresh my database it's show 6 data ,every time in refresh it's increasing).but

I can auto increment id in room database but when refresh database it's shows double

旧街凉风 提交于 2021-02-13 12:56:51
问题 In my app firstly i am fetching data from server using retrofit then it's saved in room database table then it shows in recyclerview but when i using a id as a primary key it's show only one data then this id i annotat autoGenerate = true then it's show all data which i put in server but when i reopen my app,it's show double data(this mean firstly i have 3 data in server,this app show 3 data but when i reopen or refresh my database it's show 6 data ,every time in refresh it's increasing).but

I can auto increment id in room database but when refresh database it's shows double

核能气质少年 提交于 2021-02-13 12:54:16
问题 In my app firstly i am fetching data from server using retrofit then it's saved in room database table then it shows in recyclerview but when i using a id as a primary key it's show only one data then this id i annotat autoGenerate = true then it's show all data which i put in server but when i reopen my app,it's show double data(this mean firstly i have 3 data in server,this app show 3 data but when i reopen or refresh my database it's show 6 data ,every time in refresh it's increasing).but

Room exception on table: Pre-packaged database has an invalid schema

99封情书 提交于 2021-02-11 17:25:28
问题 my task is to migrate the current architecture of our app (using Cupboard) to Room and I am encountering some issues on the very first piece of work, which is migrating the database objects, written in Java for now (Cupboard only supports Java), to make them work with Room. This is an example: public class ItemDb { public Long _id; public String type; public String subtype; public long scheduledTime; public int iteration; public String data1; public String data2; public String data3; and this

Does Android Room offer SqliteOpenHelper onCreate() & onUpdate() alternative?

眉间皱痕 提交于 2021-02-11 14:39:46
问题 Using SqliteOpenHelper, I can rely on the onCreate() method to initialize some database work if the database is created for the first time. Also, using the onUpdate() method, I can easily detect if the user has an older version of the DB and I can update it easily. Does Room support alternative methods to use? 回答1: 1. SQLiteOpenHelper.onCreate YES, there is Callback class for that. You can add Callback to RoomDatabase.Builder like this Room.databaseBuilder(getApplicationContext(), MyDb.class,

Android Room Error: Fields annotated with @Relation must be a List or Set

╄→гoц情女王★ 提交于 2021-02-11 14:17:29
问题 I want to use One to One relationship in room that available from version 2.2.0-alpha1. My current room version 2.2.5 and I get an error: error: Fields annotated with @Relation must be a List or Set. 回答1: There is change in android name since androidx. Make sure to use androidx instead of arch(deprecated) in app def room_version = "2.2.5" implementation "androidx.room:room-runtime:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version" 来源: https://stackoverflow.com