Skip to content

Instantly share code, notes, and snippets.

@mantisbayne
Created November 24, 2019 22:46
Show Gist options
  • Save mantisbayne/cd0e62e845f738187ac078e92cb97cbc to your computer and use it in GitHub Desktop.
Save mantisbayne/cd0e62e845f738187ac078e92cb97cbc to your computer and use it in GitHub Desktop.
@Database(entities = ExampleEntity::class, version = 1, exportSchema = false)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun exampleDao(): ExampleDao
companion object {
// For Singleton instantiation
@Volatile private var instance: AppDatabase? = null
fun getInstance(context: Context): AppDatabase {
return instance ?: synchronized(this) {
instance ?: buildDatabase(context).also { instance = it }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment