package com.design.mischiefgo.entity

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database(entities = [Duplicate::class], version = 1, exportSchema = false)
abstract class AppDataBase:RoomDatabase() {
    abstract fun infoDao():DuplicateDao
    companion object{
        @Volatile
        private var INSTANCE:AppDataBase?=null

        fun getDatabase(context:Context):AppDataBase{
            return INSTANCE?: synchronized(this){
                INSTANCE?:createDatabase(context).also { INSTANCE=it }
            }
        }
        private fun createDatabase(context: Context):AppDataBase{
            return Room.databaseBuilder(context.applicationContext,AppDataBase::class.java,"sound_database").fallbackToDestructiveMigration().build()
        }
    }
}