Does not support entity relations by design (e.g. no lazy loading) Database operations use SQL, no abstractions. Current stable version: 1.0.0 Created by Google
String id; public String firstName; public String lastName; } error: If a primary key is annotated with autoGenerate, its type must be int, Integer, long or Long.
public String firstName; public String lastName; } error: You must annotate primary keys with @NonNull. SQLite considers this a bug and Room does not allow it.
limit 1") fun firstUser(): User @Query("select * from User") fun allUsers(): List<User> @Query("select firstName from User") fun firstNames(): List<String> @Query("select * from User where firstName = :fn") fun findUsersByFirstName(fn: String): List<User> @Query("delete from User where lastName = :ln") fun deleteUsersWithLastName(ln: String): Int @Query("select firstName as first, lastName as last from User where lastName = :ln") fun findPersonByLastName(ln: String): List<Person> }
dao.allUsers() java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
Delivers result async with updates @Query("select * from User") fun allUsers(): LiveData<List<User>> @Query("select * from User") fun allUsersRx(): Flowable<List<User>>
String, val lastName: String, @field:TypeConverters(MyTypeConverters::class) val birthDate: Date) @Entity @TypeConverters(MyTypeConverters::class) data class User(@PrimaryKey val id: String, val firstName: String, val lastName: String, val birthDate: Date) @TypeConverters(MyTypeConverters::class) @Database(...) abstract class MyDatabase : RoomDatabase() { }
class Address(val street: String, val houseNumber: String, val city: String) @Entity class User(@PrimaryKey(autoGenerate = true) val id: Long, val name: String, val address: Address)
city column too data class Address(val street: String, val houseNumber: String, val city: String) @Entity class User(@PrimaryKey(autoGenerate = true) val id: Long, val name: String, @Embedded val address: Address)
list @Query("select * from User") fun allUsers():List<User> // Generates a PositionalDataSource (not observable) @Query("select * from User") fun allUsers(): DataSource.Factory<Int, User> // Generates a LivePagedListBuilder (observable) that uses LIMIT and OFFSET @Query("select * from User") fun allUsers(): LivePagedListBuilder<Int, User>