Table of Contents
Creating a database class
Custom database class
RoomEx, just like Room, allows the creation of a custom, abstract database class. Such a class should be marked with the @RoomExDb annotation and should implement the RoomExDbBase class.
Using this pattern, you should notice that you gain access to the RoomDatabase, aswell as to the RoomExDbBase methods.
Example
@RoomExDb
abstract class Db : RoomExDbBase() {
// Sample method...
fun retrieveDoasForEntities(entityKlasses: List<KClass<out RoomExEntity>>): List<RoomExDao<out RoomExEntity>> {
return entityKlasses.map { e -> this.fetchDaoForEntity(e) }
}
}
Note: When retrieving an instance of the database class, be sure to cast it your custom class. The chapter "Get instance of the database class" describes how to get instance of your custom database class.
Auto generated database class
When no custom class has been created, RoomEx will auto create a database class for us.
Note that in this case, the version of your database schema is always 1 and there will be no export of your schema.
You can always switch to an custom database class later on, if needed.
The chapter "Get instance of the database class" describes how to get instance of your custom database class.