Created
March 4, 2021 07:02
-
-
Save robertlevonyan/16043589e2620cb827b2fbd713d7de08 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 = [RoomMovie::class], version = 1) // an array with entites and the current db version | |
@TypeConverters(value = [DateTypeConverter::class]) // an array of all type converters | |
abstract class AppDatabase : RoomDatabase() { | |
abstract fun movieDao(): MovieDao | |
companion object { | |
@Volatile | |
private var instance: AppDatabase? = null | |
fun getInstance(context: Context): AppDatabase = | |
instance ?: synchronized(this) { | |
instance ?: buildDatabase(context).also { instance = it } | |
} | |
private fun buildDatabase(context: Context): AppDatabase = | |
Room.databaseBuilder(context, AppDatabase::class.java, "MoviewDb") | |
.fallbackToDestructiveMigration() // destructively recreate database tables or you can write your own migration | |
.build() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment