Skip to content

Instantly share code, notes, and snippets.

@mibrahimdev
Created May 29, 2018 18:09
Show Gist options
  • Save mibrahimdev/98c7b2670dacd9c7340fcf16ed0a8225 to your computer and use it in GitHub Desktop.
Save mibrahimdev/98c7b2670dacd9c7340fcf16ed0a8225 to your computer and use it in GitHub Desktop.
@Database(entities = { WeatherEntry.class , UserEntry.class}, version = 2)
//any change to tables .. you must increase version, and define a migration methodology
@TypeConverters(DateConverter.class)
public abstract class SunshineDatabase extends RoomDatabase {
...
public static SunshineDatabase getInstance(Context context) {
if (sInstance == null) {
synchronized (LOCK) {
if (sInstance == null) {
sInstance = Room.databaseBuilder(context.getApplicationContext(), SunshineDatabase.class,
SunshineDatabase.DATABASE_NAME)
.fallbackToDestructiveMigration() //recreate all tables
.build();
}
}
}
return sInstance;
}
public abstract WeatherDao weatherDao();
//this is another Dao, I created to experiment
// if It's needed to create a Room database for each DAO
//well nope, but you need to define your entities in @Database(Class[] entities)
public abstract UserDao userDao();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment