Skip to content

Commit

Permalink
feat: add classe AppDatabase
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgeTranin committed Apr 23, 2024
1 parent e616826 commit f55e2e5
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package br.com.connectattoo.local.database

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


abstract class AppDatabase : RoomDatabase(){

companion object {

private const val DATABASE_NAME: String = "connectattoo-database"

@Volatile
private var INSTANCE: AppDatabase? = null

fun getInstance(context: Context): AppDatabase =
INSTANCE ?: synchronized(this) {
INSTANCE ?: buildDatabase(context).also { INSTANCE = it }
}

private fun buildDatabase(context: Context) =
Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java, DATABASE_NAME
).build()
}
}

0 comments on commit f55e2e5

Please sign in to comment.