package com.example.jetpackdb.data.local

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@Database(
	entities = [MyNoteEntity::class],
	version = 1,
	exportSchema = false
)
abstract class MyDatabase : RoomDatabase() {

	abstract fun myNoteDao(): MyNoteDao

	companion object {
		const val DATABASE_NAME = "myDatabase1.db"

		@Volatile
		private var INSTANCE: RoomDatabase? = null

		fun getDatabase(context: Context): MyDatabase {
			val tempInstance = INSTANCE
			if (tempInstance != null) {
				return tempInstance as MyDatabase
			}
			synchronized(this) {
				val instance = Room.databaseBuilder(
					context.applicationContext,
					MyDatabase::class.java,
					DATABASE_NAME
				).build()
				INSTANCE = instance
				return instance
			}
		}
	}
}