Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Room database example
/**
* Abstract Foodium database.
* It provides DAO [DEtailsDap] by using method [getDEtailsDAO].
*/
@Database(
entities = [UserDetails::class],
version = 1,
exportSchema = false
)
abstract class AuditDatabase : RoomDatabase() {
/**
* @return [userdeatsilsDao] Audit User Data Access Object.
*/
abstract fun getDetailsDao(): UserDetailsDao
companion object {
const val DB_NAME = "audit_database"
@Volatile
private var INSTANCE: AuditDatabase? = null
fun getInstance(context: Context): AuditDatabase {
val tempInstance = INSTANCE
if (tempInstance != null) {
return tempInstance
}
synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
AuditDatabase::class.java,
DB_NAME
)
.fallbackToDestructiveMigration()
.build()
INSTANCE = instance
return instance
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment