-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e616826
commit f55e2e5
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
app/src/main/java/br/com/connectattoo/local/database/AppDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |