Skip to content

Instantly share code, notes, and snippets.

@PauloLinhares09
Created September 13, 2018 19:47
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 PauloLinhares09/f87de2b88554e469f30b8da5588bba60 to your computer and use it in GitHub Desktop.
Save PauloLinhares09/f87de2b88554e469f30b8da5588bba60 to your computer and use it in GitHub Desktop.
@Database(entities = arrayOf(Team::class, Player::class), version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun teamDao() : TeamDao
abstract fun playerDao() : PlayerDao
companion object {
var MY_INSTANCE : AppDatabase? = null
fun createInmemoryDatabse(context : Context) : AppDatabase{
if (MY_INSTANCE == null){
MY_INSTANCE = Room.inMemoryDatabaseBuilder(context.applicationContext, AppDatabase::class.java)
.allowMainThreadQueries()
.build()
}
return MY_INSTANCE!!
}
fun destroyInstance(){
MY_INSTANCE = null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment