DataBaseRoom.kt 866 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package com.example.ayudapy

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

@Database(entities = arrayOf(PedidoSave::class), version = 1)
abstract class PedidoDataBase : RoomDatabase() {

    abstract fun daoPedido(): DaoPedido
    companion object {
        private var INSTANCE: PedidoDataBase? = null

        fun getInstance(context: Context): PedidoDataBase? {
            if (INSTANCE == null) {
                synchronized(PedidoDataBase::class) {
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                        PedidoDataBase::class.java, "pedidodata.db")
                        .build()
                }
            }
            return INSTANCE
        }

        fun destroyInstance() {
            INSTANCE = null
        }
    }
}