Created
June 1, 2020 09:36
-
-
Save shamshadpattani/9a0dead73d3545213dc64eccef168586 to your computer and use it in GitHub Desktop.
Room database example
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
/** | |
* 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