Skip to content

Instantly share code, notes, and snippets.

@tobioyelekan
Last active May 24, 2020 15:41
Show Gist options
  • Save tobioyelekan/78cb5a1adc5da8094cd0fd49b21981ac to your computer and use it in GitHub Desktop.
Save tobioyelekan/78cb5a1adc5da8094cd0fd49b21981ac to your computer and use it in GitHub Desktop.
@Database(
entities = [User::class],
version = 1,
exportSchema = false
)
abstract class DatabaseClass : RoomDatabase() {
abstract fun userDao(): UserDao
companion object {
private var instance: DatabaseClass? = null
fun getDatabase(context: Context): DatabaseClass {
if (instance == null) {
synchronized(DatabaseClass::class.java) {}
instance =
Room.databaseBuilder(context, DatabaseClass::class.java, "app.db")
.fallbackToDestructiveMigration()
.build()
}
return instance!!
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment