package com.sound.prankparty.Room;

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

@Database(entities = {SaveSounds.class,FavoriteSounds.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {

    public abstract SaveSoundsDao saveSoundsDao();
    public abstract FavoriteSoundsDao favoriteSoundsDao();

    private static volatile AppDatabase INSTANCE;

    public static AppDatabase getDatabase(final Context context) {
        if (INSTANCE == null) {
            synchronized (AppDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                                    AppDatabase.class, "save_sound_database")
                            .fallbackToDestructiveMigration()  // 当数据库版本升级时，删除现有数据
                            .build();
                }
            }
        }
        return INSTANCE;
    }
}
