2020-06-06 18:45:20 +02:00
|
|
|
package org.mercury_im.messenger.android.di.module;
|
2019-10-28 14:56:56 +01:00
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
|
|
|
|
import org.mercury_im.messenger.BuildConfig;
|
2020-06-09 21:52:53 +02:00
|
|
|
import org.mercury_im.messenger.data.model.Models;
|
2019-10-28 14:56:56 +01:00
|
|
|
|
|
|
|
import javax.inject.Singleton;
|
|
|
|
|
|
|
|
import dagger.Module;
|
|
|
|
import dagger.Provides;
|
|
|
|
import io.requery.Persistable;
|
|
|
|
import io.requery.android.sqlite.DatabaseSource;
|
|
|
|
import io.requery.reactivex.ReactiveEntityStore;
|
|
|
|
import io.requery.reactivex.ReactiveSupport;
|
|
|
|
import io.requery.sql.Configuration;
|
|
|
|
import io.requery.sql.EntityDataStore;
|
|
|
|
import io.requery.sql.TableCreationMode;
|
|
|
|
|
|
|
|
@Module
|
2020-06-09 21:52:53 +02:00
|
|
|
public class AndroidDatabaseModule {
|
2019-10-28 14:56:56 +01:00
|
|
|
|
|
|
|
@Provides
|
|
|
|
@Singleton
|
|
|
|
static ReactiveEntityStore<Persistable> provideDatabase(Application application) {
|
|
|
|
// override onUpgrade to handle migrating to a new version
|
2019-12-13 11:39:35 +01:00
|
|
|
DatabaseSource source = new DatabaseSource(application, Models.DEFAULT, "mercury_req_db", 1);
|
2019-10-28 14:56:56 +01:00
|
|
|
if (BuildConfig.DEBUG) {
|
|
|
|
source.setTableCreationMode(TableCreationMode.DROP_CREATE);
|
|
|
|
}
|
|
|
|
Configuration configuration = source.getConfiguration();
|
2019-12-13 11:39:35 +01:00
|
|
|
return ReactiveSupport.toReactiveStore(new EntityDataStore<>(configuration));
|
2019-10-28 14:56:56 +01:00
|
|
|
}
|
|
|
|
}
|