Skip to content

Instantly share code, notes, and snippets.

@shkschneider
Last active November 27, 2018 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shkschneider/4626a2a7a7812c309eb356ccc165978b to your computer and use it in GitHub Desktop.
Save shkschneider/4626a2a7a7812c309eb356ccc165978b to your computer and use it in GitHub Desktop.
@Database(entities = [
User::class,
Project::class,
Notification::class
], version = 1, exportSchema = false)
abstract class MyDatabase : RoomDatabase() {
abstract fun users(): Users
abstract fun projects(): Projects
abstract fun notifications(): Notifications
companion object {
private var INSTANCE: MyDatabase? = null
fun get(context: Context): MyDatabase {
if (INSTANCE == null) {
INSTANCE = Room.inMemoryDatabaseBuilder(context.applicationContext, MyDatabase::class.java)
.allowMainThreadQueries() // FIXME never do this (coroutines to come)
.build()
}
return INSTANCE!!
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment