Skip to content

Instantly share code, notes, and snippets.

@cdmunoz
Created March 8, 2018 02:23
Show Gist options
  • Save cdmunoz/213db410557aa18b10d5b40ab5ad9977 to your computer and use it in GitHub Desktop.
Save cdmunoz/213db410557aa18b10d5b40ab5ad9977 to your computer and use it in GitHub Desktop.
@Module
class AppModule(val app: Application) {
companion object {
val MIGRATION_1_2: Migration = object : Migration(1, 2){
override fun migrate(database: SupportSQLiteDatabase) {
// Change the table name to the correct one
database.execSQL("ALTER TABLE cryptocurrency RENAME TO cryptocurrencies")
}
}
}
@Provides
@Singleton
fun provideApplication(): Application = app
@Provides
@Singleton
fun provideCryptocurrenciesDatabase(app: Application): Database = Room.databaseBuilder(app,
Database::class.java, "cryptocurrencies_db")
/*.addMigrations(MIGRATION_1_2)*/
.fallbackToDestructiveMigration()
.build()
@Provides
@Singleton
fun provideCryptocurrenciesDao(
database: Database): CryptocurrenciesDao = database.cryptocurrenciesDao()
@Provides
fun provideCryptocurrenciesViewModelFactory(
factory: CryptocurrenciesViewModelFactory): ViewModelProvider.Factory = factory
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment