@Database(entities = [NewPost::class], version = 1) | |
abstract class NewPostDatabase: RoomDatabase() { | |
abstract fun newPostDao(): NewPostDao | |
companion object { | |
private var INSTANCE: NewPostDatabase? = null | |
fun getInstance(context: Context): NewPostDatabase? { | |
if (INSTANCE == null) { | |
synchronized(NewPostDatabase::class) { | |
INSTANCE = Room.databaseBuilder(context, | |
NewPostDatabase::class.java, | |
NewPostDatabase::class.java.simpleName).build() | |
} | |
} | |
return INSTANCE | |
} | |
fun destroyInstance() { | |
INSTANCE = null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment