package cn.org.bjca.trust.push.db

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

object DbHelper {

    private lateinit var dataBase: PushDatabase

    fun getDataBase(): PushDatabase {
        if (!::dataBase.isInitialized) {
            throw Throwable("PushDatabase未初始化，请确认是否先调用了fun getDataBase(context: Context)方法")
        }
        return dataBase
    }

    fun getDataBase(context: Context): PushDatabase {
        if (!::dataBase.isInitialized) {
            val b = Room.databaseBuilder(context, PushDatabase::class.java, "pushDb")
//        .addMigrations(MIGRATION_1_2)
            b.allowMainThreadQueries() //允许在主线程 操作db
            dataBase = b.build()
        }
        return dataBase
    }

}