Skip to content

Instantly share code, notes, and snippets.

@yashprakash13
Created September 9, 2020 16:40
Show Gist options
  • Save yashprakash13/018193c4a9c755a4c5e9006ec63e917f to your computer and use it in GitHub Desktop.
Save yashprakash13/018193c4a9c755a4c5e9006ec63e917f to your computer and use it in GitHub Desktop.
@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