34 lines
982 B
Kotlin
34 lines
982 B
Kotlin
package fr.sanchezm.attestationsCovid19.data.db
|
|
|
|
import android.content.Context
|
|
import androidx.room.Database
|
|
import androidx.room.Room
|
|
import androidx.room.RoomDatabase
|
|
import fr.sanchezm.attestationsCovid19.data.db.dao.ProfileDao
|
|
import fr.sanchezm.attestationsCovid19.data.db.entity.Profile
|
|
|
|
@Database(
|
|
entities = [Profile::class],
|
|
version = 1
|
|
)
|
|
abstract class MyDatabase private constructor() : RoomDatabase() {
|
|
|
|
abstract fun profileDao(): ProfileDao
|
|
|
|
companion object {
|
|
@Volatile
|
|
private var instance: MyDatabase? = null
|
|
private val LOCK = Any()
|
|
|
|
operator fun invoke(context: Context) = instance ?: synchronized(LOCK) {
|
|
instance ?: buildDatabase(context).also { instance = it }
|
|
}
|
|
|
|
private fun buildDatabase(context: Context) =
|
|
Room.databaseBuilder(
|
|
context.applicationContext,
|
|
MyDatabase::class.java, "data.db"
|
|
)
|
|
.build()
|
|
}
|
|
} |