Skip to content

Instantly share code, notes, and snippets.

@behrends

behrends/AppDatabase.kt

Last active Nov 7, 2019
Embed
What would you like to do?
package com.example.roomexample
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database(entities = [Person::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun personDao(): PersonDao
companion object {
@Volatile private var instance: AppDatabase? = null
@Synchronized
fun getDatabase(context: Context): AppDatabase {
if(instance == null) {
instance = Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
"people.db"
).build()
}
return instance!!
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.