Does not support entity relations by design (e.g. no lazy loading) Database operations use SQL, no abstractions. Current 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> }
abstract fun insertSingleUser(user: User) @Insert protected abstract fun insertBooks(books: List<Book>) @Query("select * from User where id = :id") protected abstract fun findUserById(id: String) : User? @Query("select * from Book where userId = :userId") protected abstract fun findUserBooks(userId: String) : List<Book> @Transaction open fun insertUser(user: User) { insertBooks(user.books) insertSingleUser(user) } fun findUser(id: String) : User { val user = findUserById(id) return user?.copy(books = findUserBooks(id)) ?: throw IllegalArgumentException("No user with id $id") } }
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 TiledDataSource (not observable) @Query("select * from User") fun allUsers(): TiledDataSource<User> // Generates a LivePagedListProvider (observable) that uses LIMIT and OFFSET @Query("select * from User") fun allUsers(): LivePagedListProvider<Integer, User>