Created
September 9, 2020 16:40
-
-
Save yashprakash13/018193c4a9c755a4c5e9006ec63e917f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 = [Word::class], version = 1, exportSchema = false) | |
| abstract class WordDatabase : RoomDatabase() { | |
| abstract fun wordDao() : WordDao | |
| companion object{ | |
| // For Singleton instantiation | |
| @Volatile private var INSTANCE: WordDatabase? = null | |
| fun getInstance(context: Context): WordDatabase { | |
| synchronized(this) { | |
| var instance = INSTANCE | |
| if (instance == null) { | |
| instance = Room.databaseBuilder( | |
| context.applicationContext, | |
| WordDatabase::class.java, | |
| "word_database" | |
| ) | |
| .fallbackToDestructiveMigration() | |
| .build() | |
| INSTANCE = instance | |
| } | |
| return instance | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment