Last active
May 24, 2020 15:41
-
-
Save tobioyelekan/78cb5a1adc5da8094cd0fd49b21981ac 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 = [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