Created
March 8, 2018 02:23
-
-
Save cdmunoz/213db410557aa18b10d5b40ab5ad9977 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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