Created
July 13, 2020 13:58
-
-
Save sberoch/98b66f5f5f7a5cc3144e6a69a9ba5917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Database(entities = [Character::class], version = 1, exportSchema = false) | |
abstract class AppDatabase : RoomDatabase() { | |
abstract fun characterDao(): CharacterDao | |
companion object { | |
@Volatile private var instance: AppDatabase? = null | |
fun getDatabase(context: Context): AppDatabase = | |
instance ?: synchronized(this) { instance ?: buildDatabase(context).also { instance = it } } | |
private fun buildDatabase(appContext: Context) = | |
Room.databaseBuilder(appContext, AppDatabase::class.java, "characters") | |
.fallbackToDestructiveMigration() | |
.build() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment