-
Notifications
You must be signed in to change notification settings - Fork 13
/
TodoDatabase.kt
35 lines (27 loc) · 997 Bytes
/
TodoDatabase.kt
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
31
32
33
34
35
package com.aseemwangoo.handsonkotlin.database
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database(entities = [TodoItem::class], version = 1, exportSchema = false)
abstract class TodoDatabase : RoomDatabase() {
abstract fun todoDao(): TodoDatabaseDao
companion object {
private var INSTANCE: TodoDatabase? = null
fun getInstance(context: Context): TodoDatabase {
synchronized(this) {
var instance = INSTANCE
if (instance == null) {
instance = Room.databaseBuilder(
context.applicationContext,
TodoDatabase::class.java,
"todo_list_database"
).fallbackToDestructiveMigration()
.build()
INSTANCE = instance
}
return instance
}
}
}
}